Key press problem? (Beginner's question)

V

Valcia

Guest
so this is my code for animation transitioning
_keyL = keyboard_check_pressed(ord("L"));
_keyD = keyboard_check(ord("D"));
_keyA = keyboard_check(ord("A"));
_keySpace = keyboard_check_pressed(vk_space);

if (_keyL == true)
{
image_speed = 0.6;
sprite_index = spr_shield_combo1_R;
}
if(_keyD == true)
{
image_speed = 0.5;
sprite_index = spr_shield_run_right;
}
if(_keyA == true)
{
image_speed = 0.5;
sprite_index = spr_shield_run_left;
}
if (keyboard_check(vk_nokey))
{
image_speed = 0.2;
sprite_index = spr_shield_idle;
}


so when i write keyboard_checkbutton_pressed it is supposed to allow me to only click once and not hold on the button to perform the animation right?
But why is it that when i hold down on 'L' key. it will keep playing the animation im confuse?! Does keyboard_checkbutton_pressed not allow the player to only press button once and click again like the
jump button?
 

Nidoking

Member
Where is the part where you set the sprite_index to something else after setting it here? I see you've got a vk_nokey clause, but where is the part where you do that where it actually WORKS?

(Hint: "else" is a thing that you need to learn to use)
 

Sabnock

Member
Keyboard_check_pressed() will go straight back to false if you keep the key pressed so it will not run the code for that if statement more than the first press. however vk_nokey will still register that a key is being pressed and therefore will not run that section of code either so the sprite will keep running it's current animation until you release the L key.

Also, Nidoking is correct. you need to learn to use else as well.
 
Last edited:
Top