How do I create a functional reloading mechanic?

  • So I'm attempting to create a reloading mechanic that will automatically reload one bullet at a time, like a shotgun, that can't exceed it's max of four rounds, and draws from an ammo reserve. So basically, a single-round loading weapon that uses reserve ammo. When I try to get it to reload, it usually gives the player like 48 bullets or something like that. If I can get it to reload without going overdrive like that, I'd also like to know how to program a reserve ammo function so the player doesn't have infinite ammo.

    Here's any code I have related to reloading:

    Ammo Instance variable is set to 4 normally.

    Mouse: Left Button is down

    Soldier: Ammo > 0

    (Subevent)System: Every 0.8 seconds (reload delay)

    System: Create Object Rocket

    Soldier: Subtract 1 from Ammo.

    Text2(HUD Ammo count) Set text to Soldier.Ammo

    System: Soldier.Ammo < 4

    System: Wait 0.8 Seconds (Time between reloading each shot)

    Add 1 to Ammo

    The code above is where the issue seems to happen. It'll run a reload, and the ammo count will go to 48. I'd love to be able to set a limit, as well as getting to reload one at a time.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • System: Soldier.Ammo < 4

    System: Wait 0.8 Seconds (Time between reloading each shot)

    Add 1 to Ammo

    When (System: Soldier.Ammo < 4) >>> it will Run every Thick at last for 0.8 accumulating many many "waits & 1 Bullet" they will be delayed but all the "waits" accumulated they will have to run sooner or later if they can't run straight away they will be put on hold until they Run like in a cue that's why probably you see it jumping to 48 in one go.

    The best thing will be

    System: Soldier.Ammo < 4

    System: Every 0.8 Seconds

    >>>>>>>>>>>>> >>>>>>>>>>>>>>>Add 1 to Ammo

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