How do I randomly chose an instance variable?

Get help using Construct 2

Post » Sat Mar 28, 2015 9:27 am

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.
B
7
S
2
Posts: 102
Reputation: 975

Post » Sat Mar 28, 2015 9:46 am

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, ...)
Visual Novel 'Engine' in 100 Events
if you ever have to choose between buying Construct 2 on scirra.com or on Steam, read this: Review
B
22
S
9
G
1
Posts: 788
Reputation: 3,788

Post » Sat Mar 28, 2015 10:00 am

Which action do I use for "choose"
B
7
S
2
Posts: 102
Reputation: 975

Post » Sat Mar 28, 2015 10:03 am

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 : plugin-switchcase_t64458
B
12
S
7
G
7
Posts: 450
Reputation: 4,276

Post » Sat Mar 28, 2015 10:14 am

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
B
7
S
2
Posts: 102
Reputation: 975

Post » Sat Mar 28, 2015 10:16 am

Oh, I misread mindfaQ message, I was writing some or less the same thing.
B
12
S
7
G
7
Posts: 450
Reputation: 4,276


Return to How do I....?

Who is online

Users browsing this forum: diamantico21, ratboy3 and 31 guests