• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Help with a reload

S

Salsa

Guest
hello

I have been trying to get a reloading mechanic in my game for a little bit. right now i have it so whenever you press R you ammo will reload to the maximum you can get after about 2 seconds.
I wanted to add a spot where whenever your ammo reaches zero it will automatically reload, but for some reason this part of it is just not working. Here is the code, im wondering if someone can tell me why it is not working, or even a better way to do all of this.
thanks!
GML:
[ Both alarm events just have the same thing in it which is Sammo = 8; ]

if (keyboard_check_pressed(ord("R")))
{
    alarm[1] = 60;
    
}

if (Sammo <= 0)
{
    alarm[0] = 60;
    
}
 

chamaeleon

Member
Off you go using the debugger and/or show_debug_message() to figure out which lines of codes are or are not running, and which condition prevents it from taking place.
 

TailBit

Member
This is because it keep setting alarm 0 to 60 every step, so it will only be able to count down to 59 before it is back to 60 ..

You should check if the alarm is off (-1) before you set it
 
S

Salsa

Guest
This is because it keep setting alarm 0 to 60 every step, so it will only be able to count down to 59 before it is back to 60 ..

You should check if the alarm is off (-1) before you set it
I didnt even realize that thanks so much. i set the bottom function to have an && then wrote (alarm[0] = -1) and it seem to work fine now. THanks!
 
Top