[SOLVED] How to make an event run by pressing a key a specific number of times?

Status
Not open for further replies.

Quimey

Veteran
Veteran
Joined
Jul 9, 2020
Messages
106
Reaction score
41
First Language
Spanish
Primarily Uses
RMMV
Hey, there!

Well, the title explains pretty much what I'm in need of. Now, I'm attaching below a screenshot of the event I'm using to execute an action.
1656985093407.png
So what I need is that after the player pressed down 40 times a key, something happens, but the way it is structured, by pressing the key once, the event runs omitting the other "IF" and I don't want that.

This is what I want to trigger after the key has been pressed down 40 times:
1656985201038.png

How could I do in this case?
 
Last edited:

Trihan

Speedy Scripter
Veteran
Joined
Apr 12, 2012
Messages
5,038
Reaction score
4,650
First Language
English
Primarily Uses
RMMZ
One of the main problems you have here is that a parallel process event runs every frame, so it will take less than a second for all of these branches to return true.

I would just do one branch which increases a variable by 1, then have another branch after that which runs if the variable value is >= 40, and put a wait 1 second at the end.

You'll still run into issues when holding the key down, but it should at least work better than what you have now.
 

Quimey

Veteran
Veteran
Joined
Jul 9, 2020
Messages
106
Reaction score
41
First Language
Spanish
Primarily Uses
RMMV
One of the main problems you have here is that a parallel process event runs every frame, so it will take less than a second for all of these branches to return true.

I would just do one branch which increases a variable by 1, then have another branch after that which runs if the variable value is >= 40, and put a wait 1 second at the end.

You'll still run into issues when holding the key down, but it should at least work better than what you have now.
Like this?
1656985913538.png
Because when I press the Up key it counts to like 10 instead of 40 to run the event
 

HexMozart88

The Master of Random Garbage
Veteran
Joined
May 15, 2016
Messages
2,611
Reaction score
4,919
First Language
English
Primarily Uses
RMVXA
How do you know it's counting to 10? Are you pressing the button 10 times or do you actually see in the debug screen that it's at 10? If you're pressing the button 10 times, it's probably because you have no wait command so it's counting one button press as several.
 

Quimey

Veteran
Veteran
Joined
Jul 9, 2020
Messages
106
Reaction score
41
First Language
Spanish
Primarily Uses
RMMV
How do you know it's counting to 10? Are you pressing the button 10 times or do you actually see in the debug screen that it's at 10? If you're pressing the button 10 times, it's probably because you have no wait command so it's counting one button press as several.
Because I count the number of times I press the key. Now that I read again Trihan's comment, he suggested to add a 'Wait one second at the end'. Where should I put it?
 

Arthran

Veteran
Veteran
Joined
Jun 25, 2021
Messages
515
Reaction score
497
First Language
English
Primarily Uses
RMMZ
Because I count the number of times I press the key. Now that I read again Trihan's comment, he suggested to add a 'Wait one second at the end'. Where should I put it?
At the end (literally). Also, change the conditional from Up Arrow Pressed = 40 to Up Arrow Pressed >= 40.
 

Zeriab

Huggins!
Veteran
Joined
Mar 20, 2012
Messages
1,342
Reaction score
1,549
First Language
English
Primarily Uses
Other
Every frame you hold the key pressed down it'll increase the counter.
You need to change the logic so you wait for the player to release the button before allowing the counter to increase.
Could be something like this
  • If [Up] is pressed down
    • #0061 Up Arrow Pressed += 1
    • Loop
      • If [Up] is pressed down
        • (do nothing)
      • Else
        • Break loop
      • Wait 1 frame
  • If Up Arrow Pressed >= 40
    • #0923 ARROW PRESS SUCCESS = ON

*hugs*
- Zeriab
 

Quimey

Veteran
Veteran
Joined
Jul 9, 2020
Messages
106
Reaction score
41
First Language
Spanish
Primarily Uses
RMMV
Every frame you hold the key pressed down it'll increase the counter.
You need to change the logic so you wait for the player to release the button before allowing the counter to increase.
Could be something like this
  • If [Up] is pressed down
    • #0061 Up Arrow Pressed += 1
    • Loop
      • If [Up] is pressed down
        • (do nothing)
      • Else
        • Break loop
      • Wait 1 frame
  • If Up Arrow Pressed >= 40
    • #0923 ARROW PRESS SUCCESS = ON

*hugs*
- Zeriab
Thank you so much! I managed to get the event running with the recommendations of the other users above, however your solution seems definitive to any issue I might encounter with the previous solutions. I will apply it. Thanks a lot.
At the end (literally). Also, change the conditional from Up Arrow Pressed = 40 to Up Arrow Pressed >= 40.
Thanks! Got it working!

How do you know it's counting to 10? Are you pressing the button 10 times or do you actually see in the debug screen that it's at 10? If you're pressing the button 10 times, it's probably because you have no wait command so it's counting one button press as several.
Thanks a lot!!
 

slimmmeiske2

Little Red Riding Hood
Global Mod
Joined
Sep 6, 2012
Messages
9,845
Reaction score
6,270
First Language
Dutch
Primarily Uses
RMXP

This thread is being closed, due to being solved. If for some reason you would like this thread re-opened, please report this post and leave a message why. Thank you.

 
Status
Not open for further replies.

Latest Threads

Latest Profile Posts

Variation two of my nameless protagonist- now with color!!
WIN_20220815_21_48_46_Pro.jpg
thoughts?
Fun question - how do you manage the scope of your projects? All of my projects seem to balloon until they pop and they are suddenly nonexistent!
no I did not just have to write a song three different times because my music software doesn't support tempo changes!!
I WILL defeat this demonic USB connection notification bug
ScreenShot_8_15_2022_6_22_24.png
Mike trying to dodge the Memory Pawns invading Bantam Street. I like how the filters I used on the map almost make it look like the street is wet in a sense.

Forum statistics

Threads
124,568
Messages
1,164,457
Members
163,387
Latest member
nicklish
Top