How do I randomly chose an instance variable?

0 favourites
  • 6 posts
From the Asset Store
Easily store, modify, read and manipulate colors with Color Variables!
  • Basically what the title says. I am trying to make a boss for my game .He would have 3 variables and they would be set to false. Every X seconds he would chose one at random and make it true. When a variable is set to true he would preform an attack and then set it to false again. Each variable would represent a different attack of course.

    So have can I do it? Thanks in advance.

  • It doesn't work like this.

    Instead do:

    choose(1,2,3)

    if 1: set var 1 = true

    else if 2: set var 2 = true

    else if 3: set var 3 = true

    and since thats not really practical, it makes more sense to program it another way, maybe like this:

    every x seconds: attacktype = choose(1,2,3)

    if attacktype (not equal) 0:

    • if attacktype 1: do attack 1
    • else if attacktype 2: do attack 2
    • else if attacktype 3: do attack 3
    • : set attacktype = 0

    (ofc you can also use strings instead of 1, 2, 3, ...)

  • Which action do I use for "choose"

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Or instead of setting booleans, couldn't you set a numerical value to your variable?

    Like :

    Boss -> set attackType to int(random(1,3))

    if attackType == 1 do…

    elseif attackType == 2 do…

    elseif attackType == 3 do…

    I don't know if it could help you, but you can take a look to the switch plugin :

  • Thanks for the help guys, I did it, it needs some polishing but it works like this:

    Every X seconds- Boss/ add choose (1,2,3,4) to Attack

    Attack=1-Set animation 1,set Attack to 0

    Attack=2-Set animation 2,set Attack to 0

    Attack=3-Set animation 3,set Attack to 0

    Attack=4-Set animation 4,set Attack to 0

  • Oh, I misread mindfaQ message, I was writing some or less the same thing.

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