The Enchanted Cave 2
Delve into a strange cave with a seemingly endless supply of treasure, strategically choos
4.36 / 5.00 33,851 ViewsGhostbusters B.I.P.
COMPLETE edition of the interactive "choose next panel" comic
4.09 / 5.00 12,195 Viewshey everyone,
im back making another movie after a very long time but it seems i've run into a small problem.
I've forgotten all the action script code I had once known, and now need to figure out how to make a random number within certain limits. lets say 1 and 5. I'm using flash 8 so I guess it would have to be done in as2.
anyone know how to make a variable (randomnumber) = an actual random number?
I would appreciate the help,
thanks.
Revolution Now
random(limit) // 0 ~ < limit
Range:
var min = 1;
var max = 5;
var myNum:Number = random(max-min)+min Although practicality beats purity.
Errors should never pass silently.
In the face of ambiguity, refuse the temptation to guess.
what would i put so when the movie loads, it makes the variable, "juicy" become a random number between 1 and 5?
Revolution Now
Come on, it's not that hard. The code was self-explanitory.
random(limit) // 0 ~ < limit
var min = 1; // <- MINIMUM
var max = 5; // <- MAXIMUM
var juicy:Number = random(max-min)+min // <- Evaluates into random value. Although practicality beats purity.
Errors should never pass silently.
In the face of ambiguity, refuse the temptation to guess.
thank you, much appreciated
Revolution Now
so the code you gave me works. but why won't this work. I put it on the next frame. I think what it does is makes juicy first equal 1, then equal 2. so it goes to frame 9 every time... any ideas?
if (juicy =1) {gotoAndPlay(16);
}
if (juicy =2) {gotoAndPlay(9);
}
Revolution Now
Exactly, it makes it equal, also know as assigning the value to the variable. You are using the wrong operator, this should have been obvious if you where using the debugger to step the code. Not to mention that compilers often can be told to warn you about assignments in expressions where a condition is expected.
Each time someone abuses hittest, God kills a kitten. Please, learn real collision testing.
if (juicy ==1) {
gotoAndPlay(16);
}
if (juicy ==2) {
gotoAndPlay(9);
}
Here's what I use:
function randRange(min:Number, max:Number):Number {
var randomNum:Number = Math.floor(Math.random()*(max-min+1))+min;
return randomNum;
}
var randX:Number = randRange(10, 470); // returns 211 In terms that are a bit easier to understand, you used the wrong sign. (Called operator)
One equal sign "=" is the 'assignment' operator, and it assigns what's on the right side of it to what's on the left side of it. Example;
variable = 10; Changes variable to 10.
Two equal signs "==" is the 'evaluation' operator and it's used to compare what's on the right side to what's on the left side.
if(variable == 10)
Perpetually looking for time to return to the arts.