[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
105
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,037
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
105
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,918
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
105
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
512
Reaction score
492
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,548
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
105
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,842
Reaction score
6,257
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 Posts

Latest Profile Posts

Wheel of Attacks.png

MORE GAMBLING THEMED ATTACKS!

I AM UNABLE TO STOP!
Is it ok to repost stuff that i've posted to threads in the status feed?
If so, here's art of Shiloh, the main protagonist of the game i'm making:20220807_181702.jpg
They are meant to be ambiguous in gender, like Frisk from Undertale or Gogo from FFVI. I haven't decided what their age will be yet. Any ideas?
Please comment what you think about the art and design!
ScreenShot_8_10_2022_7_15_21.png
Looks like Mike's got a new party member in Robbi...

Calf survival story with a happy ending.
well here's that concept art!
WIN_20220812_16_53_56_Pro (2).jpg
Whaddya think? Name suggestions?

Forum statistics

Threads
124,457
Messages
1,163,809
Members
163,276
Latest member
eljugador1342
Top