# Thread: Pressing a button twice

1. ## Pressing a button twice

Hello everyone,

I need some help in making the base of my game. I would like to make my character able to run by pressing a direction button twice (Press once and hold the second one) in a short period of time. How could I make that event?

Thank you in advance.

2. ## Re: Pressing a button twice

id do something with "repete while key is pressed" it would look something like this if say shift was the button to run:

repete while left arrow is pressed
+repete while shift is pressed

player>movement>set speed to 70

if that dosent work im prety sure theres an extention for that called "control x" or control x 95

3. ## Re: Pressing a button twice

Chaos has an example of that type of movement on his site that uses the Platform Movement Object:

Examples

4. ## Re: Pressing a button twice

I don't know if there is more efficient way of doing it, but I've used alterable values for such actions in my game. I would do events like this:

+ if alterable value A > 0
+ every 0.01 seconds
- substract 1 from alterable value A

+if alterable value A < 50
+player pressed direction
- add 45 to alterable value A

+if alterable value A > 50
+repeat while player pressed direction
- set alterable value A to 60

+if alterable value A > 55
- Set max speed to (whatever is your running speed)
- Change animation sequence to running

+if alterable value A = 0
- set max speed to (your walking speed)

+if alterable value A = 0
+animation running is playing
- restore animation sequence

This means that every 0.01 seconds the alterable value is going 1 unit towards zero and if you press a direction it adds 25 to it. So if you tap direction twice in 0.40 seconds it goes over 30 and then holding a direction holds the value at 40 and the character runs. However you should take into account that you should zero the value if different direction than the last one is pressed or you have to have different counters for each direction. Otherwise it will go running if you change direction quickly.

5. ## Re: Pressing a button twice

Thanks for the help! I'll try them out as soon as I get home.

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•