Random Weapon Switch

  • 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.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • 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.

  • That worked perfectly, thankyou! Haven't steered me wrong on these forums yet, extremely helpful. Makes the process so much more enjoyable.

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