• 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 overlapping if statements

So the problem I'm having is that when I press Z it sets Z to be left, what I want to do is when I press Z you can afterward press any key and that will be left, so basically when I press Z it just sets it immediately my question is how to stop that is there perhaps a function for that?

GML:
if keyboard_check_pressed(ord("Z")) {
    thing = true;
}

if thing = true and keyboard_check_released(vk_anykey) {
    global.PlayerLeft = keyboard_lastkey
    thing = false;
}

Also, I know you can do this instead:


GML:
if keyboard_check_released(ord("Z")) {
    thing = true;
}

if thing = true and keyboard_check_pressed(vk_anykey) {
    global.PlayerLeft = keyboard_lastkey
    thing = false;
}
I'm just curious if there is another way (I changed keyboard_check_pressed to keyboard_check_released for those wondering what I changed)
 

TailBit

Member
Just change the order and clear button after setting key:
GML:
if thing = true and keyboard_check_pressed(vk_anykey) {
    global.PlayerLeft = keyboard_lastkey;
    keyboard_clear(keyboard_lastkey);
    thing = false;
}

if keyboard_check_pressed(ord("Z")) {
    thing = true;
}
 
Just change the order and clear button after setting key:
GML:
if thing = true and keyboard_check_pressed(vk_anykey) {
    global.PlayerLeft = keyboard_lastkey;
    keyboard_clear(keyboard_lastkey);
    thing = false;
}

if keyboard_check_pressed(ord("Z")) {
    thing = true;
}
Thank you so much I didn't know that step events had an order or that keyboard_clear even existed
 
Top