Ammunition and reloading

  • Hello! I have been working with construct for more than 1 year and let me just get it out there, it is the best tool for creating small games all by yourself rather quickly!

    I now have a problem that I can't seem to find the answer to, so the problem is that I want to make this reloading system that you would expect to find in a modern shooter. There are 2 numbers on the screen: one that says how much ammo is in your magazine and the other that indicates how much ammo you have "in your pocket" so what I have come up with is this: (a is the ammo in your magazine and b the "ammo in your pocket")

    on reload animation finished: set a to 12-a (12 is the maximum number of rounds you can have in your magazine)

    set b to b-12+a

    and the problem is that when you have less than 6 round in the magazine and less than 6 rounds in "the pocket" it sets the value of B to a negative value, example: 6-12+5 = -1

    I would love if anyone would give me a solution to this! (I USE CONSTRUCT 2 FOR NOW)

  • So a is the ammo in your magazine, b the "ammo in your pocket"

    Create a local variable reloadAmmo, then do this:

    Set reloadAmmo to min(12-a, b)
    Subtract reloadAmmo from b
    Add reloadAmmo to a
    
  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Thank you so much, kind sir/lady, you helped me a lot!

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