Skip to main content
Inspiring
December 25, 2015
Answered

Random Number ( if's)

  • December 25, 2015
  • 1 reply
  • 321 views

Hello, I wonder how I can randomly select a condition, the following code has been made, but only the condition 2 is used, as can for to be randomly selected one of theconditions?

Grateful!

var luck:Number = 3;

if (luck == 1) {

   gotoAndPlay(1);   

   return 0;

}

if(luck == 2) {

   addChild(movie);  

}

if(luck == 3) {

   gotoAndPlay(1);

   return 0;

}

This topic has been closed for replies.
Correct answer

var luck:uint = Math.abs(Math.random() * 3);

But this returns a random number between 0,1,2 so you have to change it to:

if (luck == 0){

if (luck == 1){

if (luck == 2){

1 reply

Correct answer
December 26, 2015

var luck:uint = Math.abs(Math.random() * 3);

But this returns a random number between 0,1,2 so you have to change it to:

if (luck == 0){

if (luck == 1){

if (luck == 2){