Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Random Number ( if's)

Explorer ,
Dec 25, 2015 Dec 25, 2015

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;

}

TOPICS
ActionScript
304
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Deleted User
Dec 25, 2015 Dec 25, 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){

Translate
Guest
Dec 25, 2015 Dec 25, 2015
LATEST

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){

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines