Help for simple random-script

hello scripting-pro’s!

i am totally new in scripting and i need some help. can you please post me a script where ich can play a movie randomly? Its for blinking eyes of an character.
The movie-sequence shuts the eyes and i already names the frame “blink” and it will rewind to frame 1

So it tried something in action - BUT I KNOW THAT THIS IS TOTALLY WRONG!!:

stop();
set var = “number”
set var = “count”
number = random (0-1000);
count from 0-1000
if(count=number){
play “blink”
}
end if

thanky so much for your help

how about something like this? I dont have flash here so i can check it, but it should have a 50% chance of blinking per frame now.


this.onEnterFrame = function() {
var i = Math.random()*10;
if (i > 5) 
goToAndPlay("blink");
};

probably want a little smaller chance than that for it to blink, something like this:

this.onEnterFrame = function() {
  if (Math.random() < 0.15) gotoAndPlay("blink");
};

but, tinoman, to translate your psuedo-code to actionscript, it would be something like this:

var number = Math.floor(Math.random()*1000);
var count = 0;
this.onEnterFrame = function() {
  if (count++ == num) gotoAndPlay("blink");
};

couldnt you

math.random(1000)

?

Careful, Brainy, typo, and naming your variable number was a bad idea :evil:

var num = Math.floor(Math.random()*1000);
var count = 0;
this.onEnterFrame = function() {
  if (count++ == num) gotoAndPlay("blink");
};

*Originally posted by morse *
**couldnt you

math.random(1000)

? **
No :slight_smile: Check the AS dictionary…

Oh I see. I didn’t realize there was a difference between math.random() and random()

Yeah, that’s not very clever from Macromedia :-\

Thanks, guys, the first script from brainy works fine - but i decreased the amount of blinks by setting the value to 0.01

But what does this means? I mean what is this number? First i set this to 3 but then nothing happened… (just for understanding the way to script random things…)

well, Math.random returns a random number between 0 and 1. so if you check if its lower than 0.01, you have about a 1% chance of “blinking”… (as its 0.01 times blink versus 0.99 not blink)… see my point? :slight_smile:

thanks, now I understand!

cheeers…