GameMaker [Solved] Double Tapping Movement Keys For Dash

S

Sahibjot Cheema

Guest
I've already created dashing, I just wanted to know if anyone knows how to detect if right arrow or left arrow as been pressed twice in a short amount of time. Thanks
 

Slyddar

Member
You can set a timer to zero on key release. Ensure it counts up per step, and every time a key is pressed check if that timer is under 30 or so, which would indicate a double tap.
 
S

Sahibjot Cheema

Guest
You can set a timer to zero on key release. Ensure it counts up per step, and every time a key is pressed check if that timer is under 30 or so, which would indicate a double tap.
I created this but theirs a bug. You can move to one direction for a while then let go and it will register as dash but I only want it to dash when you press the key twice fast. Is their a way to detect when a button is pressed but it can only be detected the first time?
 

Slyddar

Member
Yep, use keyboard_check_press() will run code the first step it's pressed only.
keyboard_check_pressed() will run code for every step it's being pressed.

EDIT:
Whoops, sorry, wrote this fast on a phone. keyboard_check_press was a mistake, I was meant to write keyboard_check_pressed. The context sensitive help should of showed only a few options anyway when you started typing it. Glad you sorted it out.
 
Last edited:
S

Sahibjot Cheema

Guest
Yep, use keyboard_check_press() will run code the first step it's pressed only.
keyboard_check_pressed() will run code for every step it's being pressed.
I don't think keyboard_check_press() exists. It doesn't register in GM and I can't find it online either. Btw I found out keyboard_check_pressed() does what you thought keyboard_check_press() does. I just found this out and everything works perfectly. Wish I found this out sooner. Thx though :D

Edit: I think you were trying to say this, "With this function you can check to see if a key has been pressed or not. Unlike the keyboard_check function, this function will only run once for every time the key is pressed down, so for it to trigger again, the key must be first released and then pressed again." It's from the GM wiki.
 
Last edited by a moderator:
E

ender22782

Guest
Create a "state" variable on your object, and set it to "no press". On the Key Pressed event, check to see if it is currently set it to "no press" - if so, set it to "pressed" and start your timer; if it is already set to "pressed", set it back to "no press", stop your timer, and run your double-tap code. If you do not press the key the second time and the timer expires, have it run your single-press code, reset the timer, and set the variable back to "no press".
 

TheouAegis

Member
The timer part is right, but unless you want right-leeft-dash or left-right-dash, then you will need to store the last key pressed or make sure the player is going the same direction.
 

Slyddar

Member
I don't think keyboard_check_press() exists.
Whoops, sorry, wrote this fast on a phone. keyboard_check_press was a mistake, I meant to write keyboard_check_pressed. The context sensitive help should of showed only a few options anyway when you started typing it. Glad you sorted it out.
 

GMWolf

aka fel666
I should mention that there are gesture events to help you with all that.
It will allow you to only have taps registered as taps, double taps as double taps (without registering the first tap), and drags as drags (without registering the initial tap).
 

AiChi

Member
I don't think keyboard_check_press() exists. It doesn't register in GM and I can't find it online either. Btw I found out keyboard_check_pressed() does what you thought keyboard_check_press() does. I just found this out and everything works perfectly. Wish I found this out sooner. Thx though :D

Edit: I think you were trying to say this, "With this function you can check to see if a key has been pressed or not. Unlike the keyboard_check function, this function will only run once for every time the key is pressed down, so for it to trigger again, the key must be first released and then pressed again." It's from the GM wiki.
I am trying to use this for running: first the keyboard_check_pressed will set the timer and if I press the same key again and timer is on, I can run. The problem is that the time is still counting and as soon as it's off, it stops my running session.

Can you please clarify how did you achieve that? I keep failing to figure it out.

Thanks a lot.
 

AiChi

Member
EDIT: of course that after I gave up the searching clues online and tried some other options, I figured it out:


Code:
    // set Timer for running
    if (right_run_released) or (left_run_released) {
        alarm[0] = 5;
    }

    // check left or right run and enable it
    if alarm[0] >= 0 {
        if right_run_pressed or left_run_pressed {
        ableToRun = true;
        }
    }
 
    // when running, double speed
    if ableToRun == true {
        maxSpeed = 10;
        sprite_index = sPlayerRun;
        if left_run_released or right_run_released {
        ableToRun = false;
        maxSpeed = 5;  
        }
    }
It's working great, but I am not entirely sure if any line of this code is needless.. ?

I am sorry for double post, I couldn't edit my previous message
 
Top