GML How to check for two keys pressed at the same time

J

josefflorian

Guest
Hi guys,

I am new to this group and very new to coding. I am trying to create a dash function on a platformer when the user hits 'X' on the keyboard. I have managed to do it succesfully when I do a keyboard check for vk_left, up, down and right individually.

Now I also want to do it in the 4 diagonal directions, so I need to tell game maker to dash diagonally if TWO keys are pressed along with 'X'. I have consulted the manual and tried to find the solution to no avail even though this seems rather basic.

Here's the part that isn't working:

if keyboard_check(vk_left) and keyboard_check (vk_up)
{
gravity = 0;

vspeed = -30;

friction = 5;

hspeed = -30;

dash = 1;

abletomove = 1;

alarm_set(0, 15);
}

Am I missing something here?
 
L

Ludo Design

Guest
What comes after this code? Specifically, look for anything that changes the vspeed or hspeed.

More details about it not working will help. What steps do you take in your game to reproduce this not functioning result? Where in your game are you testing it? Is the character standing on the ground?
 
J

josefflorian

Guest
Hi,

I just managed to figure out the source of the problem. It seems the order with which I was checking and adding else functions was wrong. I have managed to make it work sorting out the order.
 
Top