i’m making a little game, and the way i’m planning to do it uses the setInterval command. (i think i’m doing it in an odd way, but i’m not experienced with AS so…)
anyway, i was wondering if it is very memory-intensive? because i’ve made a variety of frames which the player does things on, while it pauses (setInterval) before continuing. Anyway, when i run it, it seems to slow down and become uneven in pausetimes (even though i’ve set the same number for them all) before finally just stopping
If so, is there another way to pause, while still allowing movie clips etc to keep going?
also, i need to use the gotoandplay command to a random frame from 1-20, but it says that the ‘random’ command is deprecated, so i should use math.random… problem is, it gives a value b/w 0 and 1, so the only thing i can think of is doing goToAndPlay(random(20))
any other options?
i’m trying to think of other ways to format my game…
if i put the different situations into separate movie clips, could i then make one ‘host’ clip and call the individual ones into it randomly? i guess it would be kinda like loadMovie but with a movieclip instead of a separate swf or jpeg…
and thanks for that help about the math.random thingy
That random command could be better. There is a slight chance that the outcome will be 0, wich you don’t want. Deprecated means that it can go in the next version of flash, but does not mean it’s wrong to use.
gototAndPlay(random(20));
// or
gotoAndPlay(Math.round(Math.random() *19) +1);
*Originally posted by [m] *
**That random command could be better. There is a slight chance that the outcome will be 0, wich you don’t want. **
random(20) returns a random integer between 0 and 20 including 0. If you dont want to get a 0, use the following code:[AS]Math.ceil((Math.random())*20)[/AS]
Originally posted by claudio
*random(20) returns a random integer between 0 and 20 including 0. If you dont want to get a 0, use the following code:[AS]Math.ceil((Math.random())20)[/AS]
I guess I should say that I used to think the same thing… senocular proved me wrong.
Im really confused Kax… :hangover: Ive used the trace command hundreds of times and i got no 0 using[AS]Math.ceil(Math.random()*20);[/AS]I thought that Math.ceil returns the closest integer that is greater than or equal to the specified number. So i thought that it would never return 0.
Yeah, Math.ceil rounds the number to the closest integer that is greater than or equal to the number. That’s correct.
The problem is not the number returned by Math.ceil. The problem is the number returned by Math.random, which could be 0 (unlikely, but still a possibility).
Hmm yea i get it. Thanks for the info Kax :thumb:
I see theres a slight chance that i get 0 using my code. Although I just ran a test using the trace command 7800 times and still got no 0!
Ahhhh
i’m just sticking with the random(20), seems to suit my purposes for now… i’ll have a play around with it sometime
i also stopped using the setInterval command, opting for a tedious time-consuming manual version (inserting heaps of blank frames) because it seemed to keep lagging me…