View Full Version : help for simple random-script
tinoman
May 9th, 2003, 11:04 PM
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
sweepah
May 10th, 2003, 03:15 AM
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");
};
brainy
May 10th, 2003, 03:15 PM
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");
};
morse
May 11th, 2003, 06:17 PM
couldnt you
math.random(1000)
?
pom
May 11th, 2003, 06:19 PM
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");
};
pom
May 11th, 2003, 06:20 PM
Originally posted by morse
couldnt you
math.random(1000)
? No :) Check the AS dictionary...
morse
May 11th, 2003, 06:26 PM
Oh I see. I didn't realize there was a difference between math.random() and random()
pom
May 11th, 2003, 06:36 PM
Yeah, that's not very clever from Macromedia :-\
tinoman
May 11th, 2003, 11:02 PM
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...)
brainy
May 12th, 2003, 03:33 AM
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? :)
tinoman
May 14th, 2003, 08:38 PM
thanks, now I understand!
cheeers...
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.