Beginner Question: Same Key to draw/holster weapon

G

Graphixx_03

Guest
Hi there, new to the forums, but thought it would be a good place to find the answer to this:

I’m sure it’s simple, but I want the “shift” key to draw weapon when it’s holstered, but also use the same key to holster it when it’s drawn..

The code I expected to work ended up just looping and quickly drawing and Holstering again. Ive got all the sprites to change as needed but trying to figure out how to get this to work properly.

Thanks in advance!
 
A

Annoyed Grunt

Guest
Make sure to check for presses of the key and not for the key being held. Depending on what method you are using, this translates to using the Key Pressed Event instead of the Key Down Event or keyboard_check_pressed() instead of keyboard_check().
The difference is simple: checking for the key press won't allow looping since pressing a key is an action that lasts only a single step and the user must raise and lower the key again for it to happen a second time. On the other hand, checking for the key being held down is an action that lasts throughout multiple steps.
 

Gamebot

Member
You may need another var also?

Create:
Code:
// Are we allowed to draw our weapon OR put it back. We don't want continuous looping if something is true to false
can_use = false;
draw = false;
Step:
Code:
if (vk_shift) {can_use = true}
if (can_use) {draw = !draw}

if (draw) {change sprite index/speed ect}
else {other sprite index/speed ect}
Animation end:
Code:
can_use = false;
 
V

van0014

Guest
To handle any 'debounce' looping, pressing the key should set an alarm or variable that counts to 0. Then set the button so it won't work during the cooldown, so it can't even loop on a quick double press
 
Last edited by a moderator:
Top