Random Weapon Switch

Get help using Construct 2

Post » Thu Nov 07, 2013 3:52 am

Hey again guys.
I've got a small detail I'm trying to work out.
When my player has shot an enemy I add one to a global variable, when that global variable = 5 the players weapon changes. Currently set up as
Global Variable = 5 -> Set Global Variable 'gun' to (x)

And of course when global variable gun1 = shotgun, 2= rifle etc.
I can get it to work perfectly if I choose a single number/weapon, but I have a number of random weapons I want it to randomly choose.
I've tried :
Global Variable = 5 -> Set Global Variable 'gun' to floor(random(3))

But am having issues. Sometimes two guns spawns, sometimes it works, sometimes the gun disappears. I'm wondering if there's a simpler way to do this or maybe I am using the wrong expressions to select a global variable.

B
7
S
2
Posts: 24
Reputation: 569

Post » Thu Nov 07, 2013 8:28 am

Not sure if this is your problem. But when you use Random(3) it will select a random number from 0 to 2 and not from 1 to 3.

If your range of weapons are from 1 to 3, you can try using this:

int(Random(1,3)) or int(Random(3)+1)

Both will select a random number from 1 to 3 as a non float value and round to nearest integer.

nimos1002013-11-07 08:30:35
B
44
S
11
G
2
Posts: 1,182
Reputation: 6,848

Post » Fri Nov 08, 2013 4:33 am

That worked perfectly, thankyou! Haven't steered me wrong on these forums yet, extremely helpful. Makes the process so much more enjoyable.
B
7
S
2
Posts: 24
Reputation: 569


Return to How do I....?

Who is online

Users browsing this forum: brunopalermo, dop2000, MaxxMunnn, richcoz81 and 33 guests