is there a way to get what the previous value of a variable was?

ETHC33

Member
in my case im trying do do something where if the right mouse button isn't down, to make my current_gun variable whatever it was before you hit right mouse button. I just have two guns and while the right mouse button is down you are holding your shield which is really just a different sprite for the gun. When you release it i want my current_gun to be spr_pistol or spr_rifle, whichever you had on before. That probably doesnt make sense i can explain more if you need it.
 

ome6a1717

Member
If I understand correctly, I would just add another variable called prev_gun and when you hit right mouse button, set prev_gun = current_gun. Then when you let go, you can set current_gun back to prev_gun.
 

ETHC33

Member
ok, just tried it, since current_gun = the shield, setting prev_gun to current gun just makes prev_gun the shield
 
Only set prev_gun whenever you set current_gun. And set prev_gun first:
Code:
if (keyboard_check(vk_up)) {
   prev_gun = current_gun;
   current_gun = new_gun;
}
Don't set prev_gun to current_gun every step.
 
Top