The online racing simulator
random number in flash
(5 posts, started )
#1 - ZORER
random number in flash
Hello guys,

i need help on a very simple thing.

What i can't do is, there's a movieclip being played and when it comes to a frame i want it to stop and generate a number between 0-5 and keep playing if the number is 3.If it's not 3 it should randomize it again and keep running like that.

Did this but not working.

x = Math.random()*5;
if (x = 3) {
play();
}
gotoAndPlay(1);

Thanks for any help.
Isn't == the equality operator in actionscript, rather than = ?

if (x == 3) might do it.

Edit: You'll also need to convert x to an integer. Math.random() * 5 will be a floating-point number, so it needs rounding down:

x = Math.floor(Math.random()*5);

Edit again: And it will produce a number between 0 and 4, not 0 and 5. You want to multiply by 6 to get a number between 0 and 5, or use Math.ceil() to get a number between 1 and 5.
#3 - ZORER
ow thanks, but it doesn't run with "==" and "Math.floor" added .


OK SOLVED!.

Somehow it didn't start playing on the first frame so i moved the action script to first frame now it works.

Thanks for your help!

edit:
first frame;

x = Math.floor(Math.random()*5);
if (x == 3) {
gotoAndPlay(3);
}

second frame;

gotoAndPlay(1);

it runs like that.
Really? This should work:

x = Math.floor(Math.random()*6);
if (x == 3) {
play();
}
gotoAndPlay(1);

It's been years since I used Flash but that's a pretty simple lump of code, hard to hide a syntax error in there. Are you getting any error messages from the console?
#5 - ZORER
Nope i didn't get any errors.
it just didn't seem to start playing. i traced numbers of frames but it was just stucked on first frame. When i moved the script to first frame it started running.

strange isn't it?

random number in flash
(5 posts, started )
FGED GREDG RDFGDR GSFDG