GameMaker: Studio

GameMaker: Studio

View Stats:
PuniNeko May 18, 2020 @ 2:33am
Need help with the "switch" statement
I started creating my very first game, and I decided to do a basic platformer to learn how everything works.
I managed to add walljump and double jump, but I now have a small problem with the dash.

Created this code and it functions:

if (dashcount >= 1) && (key_shift) && ((key_right) || (key_left))
{
if (key_right)
{
dashcount -= 1;
dashing = true;
hsp = 18;
vsp = 0;
alarm[1] = 10;
}
if (key_left)
{
dashcount -= 1;
dashing = true;
hsp = -18;
vsp = 0;
alarm[1] = 10;
}
}

My problem is that I'd first tried to use the "switch" statement like this:

switch(keyboard_key)
{
case(ord("A")):
dashcount -= 1
dashing = true;
hsp = -18;
vsp = 0;
alarm[1] = 10;
break;
case(ord("D")):
dashcount -= 1
dashing = true;
hsp = 18;
vsp = 0;
alarm[1] = 10;
break;
}

What happened is that in order to dash, I had to press my "dash key" and "A" or "D" exactly at the same moment, which is hardly doable.
Is there a way to use the "switch" statement rather than 2 "ifs" and still being able to hold down "A" or "D" and THEN press the "dash key" in order to dash?

Thanks for you time!
< >
Showing 1-1 of 1 comments
The Winter Bud May 19, 2020 @ 5:20am 
I would play with the logic. I did something like this:
key_dash=keyboard_check(vk_shift); if(key_dash){ switch(keyboard_key){ case ord("D"): x+=5; break; case ord("A"): x-=5; break; } }
and the object responded accordingly. While holding the shift key down I can press the (D) key and make the object move right and pressing the (A) key makes the object move left.

EDIT: the object doesn't move at all if I'm not holding down the shift key.
Last edited by The Winter Bud; May 19, 2020 @ 6:47am
< >
Showing 1-1 of 1 comments
Per page: 1530 50