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

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?
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.
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
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.
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?
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.
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
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!!

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.

Original thread: https://forums.rpgmakerweb.com/threads/solved-how-to-make-an-event-run-by-pressing-a-key-a-specific-number-of-times.149183/