0 Favourites

Why don't my random instance vairables work? [SOLVED]

  • What I want is for a player to click on Sprite1 and the game to randomly take them either to Layout1, Layout2 or Layout3.

    (Sprite_roll is the name of my instance variable)

    Why doesn't this work?:

    left button clicked on Sprite1 -- set Sprite_roll to random(3)

    Sprite_roll=0 -- go to Layout1

    Sprite_roll=1 -- go to Layout2

    Sprite_roll=2 -- go to Layout3

    but this DOES work:

    left button clicked on Sprite1 -- set Sprite_roll to random(10)

    Sprite_roll<5 -- go to Layout1

    Sprite_roll>5 -- go to Layout2

    I'm sure I'm missing something obvious but to me this looks like it should work.

    Thanks for any help!

  • Construct 3

    Buy Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Buy Now Construct 3 users don't see these ads
  • What I want is for a player to click on Sprite1 and the game to randomly take them either to Layout1, Layout2 or Layout3.

    (Sprite_roll is the name of my instance variable)

    Why doesn't this work?:

    left button clicked on Sprite1 -- set Sprite_roll to random(3)

    Sprite_roll=0 -- go to Layout1

    Sprite_roll=1 -- go to Layout2

    Sprite_roll=2 -- go to Layout3

    but this DOES work:

    left button clicked on Sprite1 -- set Sprite_roll to random(10)

    Sprite_roll<5 -- go to Layout1

    Sprite_roll>5 -- go to Layout2

    I'm sure I'm missing something obvious but to me this looks like it should work.

    Thanks for any help!

    The "=" compare will not work, because random(3) will give you a number like 2.33434 or something like that. int(random(3)) or floor(random(3)) will set variable to normal numbers 0 or 1 or 2 or 3.

  • SWEEET! Thanks so much for your help! SOLVED

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)