Need Help with Button Mashing Event

I know I have posted a help thread before, but I got nothing, so yeah 😀

I am trying to make an event where the player has to spam a button in order to open a door or else they will die.

To be more specific:
Spam Ok 20 times or gameover.

Can anyone show me a script for this?

Thanks 🙂
Ok you don't need a script, you can do this with events. Let me explain. We'll need 2 events for that: one event that will kick start the timer (will only be triggered once), and another event to count the number of times a button is pushed (in this case Enter or Z) and to check if the player has pushed the button enough times at the end of the timer.

So the first event can be anything, but it can only be triggered once at the beginning of the process: Set the timer to the amount of time you want (I put 10 seconds in this example) and set a Switch to ON to identify that the timer has been activated.


1580766512571.png



Okay, the second event is a parallel process event (meaning that the event is being triggered once per frame) which has the switch for the timer previously defined as a condition. Here you'll create the button counter logic and handle the result after the timer. Here's how I done it:

1580766596365.png


So that should work. If you want the mini-game to be able to repeat, be sure to reset the variable counting the number of times the button has been pushed.
You can do this entirely through events, no script required. Just change the timer value and variable to store the number of button presses
1580766594225.png
Ok you don't need a script, you can do this with events. Let me explain. We'll need 2 events for that: one event that will kick start the timer (will only be triggered once), and another event to count the number of times a button is pushed (in this case Enter or Z) and to check if the player has pushed the button enough times at the end of the timer.

So the first event can be anything, but it can only be triggered once at the beginning of the process: Set the timer to the amount of time you want (I put 10 seconds in this example) and set a Switch to ON to identify that the timer has been activated.


View attachment 133223


Okay, the second event is a parallel process event (meaning that the event is being triggered once per frame) which has the switch for the timer previously defined as a condition. Here you'll create the button counter logic and handle the result after the timer. Here's how I done it:

View attachment 133225

So that should work. If you want the mini-game to be able to repeat, be sure to reset the variable counting the number of times the button has been pushed.

Thank you so much 😀
You can do this entirely through events, no script required. Just change the timer value and variable to store the number of button presses
View attachment 133224

This helps thx
You might want to increase the number of button presses required, because loops and parallel processes fire off every frame, even pressing the Ok button once is likely to increase the number of button presses recorded by a lot more than 20
Try to not double-post (two posts following each other from the same person in less than 72 hours), edit your posts to add missing information. I'm just informing you for next time, nothing to worry about. (the blue text is auto-generated, don't be intimidated by it lol)

@Nightfight , please avoid double posting, as it is against the forum rules. You can use the "Edit" function on your posts to add additional information you've forgotten or respond to multiple people. You can review our forum rules here. Thank you.


And @rainyday just made me realize that the input condition is an Input.isPressed (will count if the button is pressed down) and not an Input.isTriggered (will not count if the button is pressed down, you have to pushed a second time). If you prefer the trigger method (which does not count when the button is pressed down), you have to modify the parallel event I made. Use this instead:

1580768224763.png
The Input.isTriggered check is neat~ 😂

Another option is to use a switch to track whether the button was up or down last frame, e.g.
Spoiler: Event example
Code:
◆Comment:Initialise timer duration and button-mash count.
◆Control Variables:#0042 timer = 5
◆Control Variables:#0041 count = 20
◆Text:None, Window, Bottom
:    :Press the action button \v[41] times
:    :in \v[42] seconds to win!
◆Comment:Convert from seconds to frames.
◆Control Variables:#0042 timer *= 60
◆Comment:Small loop: wait for button not pressed down before starting.
◆Loop
  ◆If:Button [OK] is pressed down
    ◆Wait:1 frame
    ◆
  :Else
    ◆Break Loop
    ◆
  :End
  ◆
:Repeat Above
◆Comment:Start timer just for visuals.
◆Control Timer:Start, 0 min 5 sec
◆Comment:Big loop: get timed input!
◆Loop
  ◆If:buttonDown is ON
    ◆Comment:Button is pressed down, check for release
    ◆If:Button [OK] is pressed down
      ◆Comment:(nothing)
      ◆
    :Else
      ◆Comment:-1 to counter, we're getting closer~
      ◆Control Switches:#0006 buttonDown = OFF
      ◆Control Variables:#0041 count -= 1
      ◆Comment:Animation, just because.
      ◆Show Animation:Player, Wind One 1
      ◆
    :End
    ◆
  :Else
    ◆Comment:Button is released, check for next press
    ◆If:Button [OK] is pressed down
      ◆Control Switches:#0006 buttonDown = ON
      ◆
    :End
    ◆
  :End
  ◆Comment:Advance the timer
  ◆Control Variables:#0042 timer -= 1
  ◆Comment:Check for end conditions
  ◆If:count ≤ 0
    ◆Comment:Mash success! End loop.
    ◆Break Loop
    ◆
  :End
  ◆If:timer ≤ 0
    ◆Comment:Time up! End loop.
    ◆Break Loop
    ◆
  :End
  ◆Comment:Wait 1 frame before looping again.
  ◆Wait:1 frame
  ◆
:Repeat Above
◆Comment:Stop timer.
◆Control Timer:Stop
◆Text:None, Window, Bottom
:    :Mash remaining: \v[41] mashes
:    :Time remaining: \v[42] frames
◆If:count ≤ 0
  ◆Text:None, Window, Bottom
  :    :You win!
  ◆
:Else
  ◆Text:None, Window, Bottom
  :    :Be faster next time!
  ◆
:End
Typically I recommend using an Autorun trigger with Loop/Break Loop commands like this, rather than Parallel trigger, but it depends on the exact situation in your game. 😮‍💨
Ok you don't need a script, you can do this with events. Let me explain. We'll need 2 events for that: one event that will kick start the timer (will only be triggered once), and another event to count the number of times a button is pushed (in this case Enter or Z) and to check if the player has pushed the button enough times at the end of the timer.

So the first event can be anything, but it can only be triggered once at the beginning of the process: Set the timer to the amount of time you want (I put 10 seconds in this example) and set a Switch to ON to identify that the timer has been activated.


View attachment 133223


Okay, the second event is a parallel process event (meaning that the event is being triggered once per frame) which has the switch for the timer previously defined as a condition. Here you'll create the button counter logic and handle the result after the timer. Here's how I done it:

View attachment 133225

So that should work. If you want the mini-game to be able to repeat, be sure to reset the variable counting the number of times the button has been pushed.
[/QU
The Input.isTriggered check is neat~ 😂

Another option is to use a switch to track whether the button was up or down last frame, e.g.
Spoiler: Event example
Code:
◆Comment:Initialise timer duration and button-mash count.
◆Control Variables:#0042 timer = 5
◆Control Variables:#0041 count = 20
◆Text:None, Window, Bottom
:    :Press the action button \v[41] times
:    :in \v[42] seconds to win!
◆Comment:Convert from seconds to frames.
◆Control Variables:#0042 timer *= 60
◆Comment:Small loop: wait for button not pressed down before starting.
◆Loop
  ◆If:Button [OK] is pressed down
    ◆Wait:1 frame
    ◆
  :Else
    ◆Break Loop
    ◆
  :End
  ◆
:Repeat Above
◆Comment:Start timer just for visuals.
◆Control Timer:Start, 0 min 5 sec
◆Comment:Big loop: get timed input!
◆Loop
  ◆If:buttonDown is ON
    ◆Comment:Button is pressed down, check for release
    ◆If:Button [OK] is pressed down
      ◆Comment:(nothing)
      ◆
    :Else
      ◆Comment:-1 to counter, we're getting closer~
      ◆Control Switches:#0006 buttonDown = OFF
      ◆Control Variables:#0041 count -= 1
      ◆Comment:Animation, just because.
      ◆Show Animation:Player, Wind One 1
      ◆
    :End
    ◆
  :Else
    ◆Comment:Button is released, check for next press
    ◆If:Button [OK] is pressed down
      ◆Control Switches:#0006 buttonDown = ON
      ◆
    :End
    ◆
  :End
  ◆Comment:Advance the timer
  ◆Control Variables:#0042 timer -= 1
  ◆Comment:Check for end conditions
  ◆If:count ≤ 0
    ◆Comment:Mash success! End loop.
    ◆Break Loop
    ◆
  :End
  ◆If:timer ≤ 0
    ◆Comment:Time up! End loop.
    ◆Break Loop
    ◆
  :End
  ◆Comment:Wait 1 frame before looping again.
  ◆Wait:1 frame
  ◆
:Repeat Above
◆Comment:Stop timer.
◆Control Timer:Stop
◆Text:None, Window, Bottom
:    :Mash remaining: \v[41] mashes
:    :Time remaining: \v[42] frames
◆If:count ≤ 0
  ◆Text:None, Window, Bottom
  :    :You win!
  ◆
:Else
  ◆Text:None, Window, Bottom
  :    :Be faster next time!
  ◆
:End
Typically I recommend using an Autorun trigger with Loop/Break Loop commands like this, rather than Parallel trigger, but it depends on the exact situation in your game. 😮‍💨

wait how would i add that (using script)
You can do this entirely through events, no script required. Just change the timer value and variable to store the number of button presses
View attachment 133224

I am having a problem. The code works, but it cant fail. Here is the code

@Nightfight , please avoid double posting, as it is against the forum rules. You can use the "Edit" function on your posts to add additional information you've forgotten or respond to multiple people. You can review our forum rules here. Thank you.


As I said, it can't fail because the "Button is pressed down" condition will add +1 to the count every FRAME that the button is held down. If you want to count the amount of individual click of the button, you need to use the script condition (page 4 of the conditional branch page in the event menu). See my previous post where I corrected it (the post where I told you not to double-post 😛 )
Like @MushroomCake28 said, because it registers it for each frame, 20 presses is way to low. Either use their solution that only triggers once or increase your check by a lot(you can use f9 to check the value of the variable)
I have the feeling this could be done more simple.
Every Time you press the Action Button next to the Event, it will count a Variable up, +1 each time
until its 20 or more.
ahelp495.PNG
.... I have an evented tutorial with a demo for that (including drawing a temporary bar) if you are interested doing it this way. The mashing is part of the bonus.
.... I have an evented tutorial with a demo for that (including drawing a temporary bar) if you are interested doing it this way. The mashing is part of the bonus.


Oh dang that looks really cool. Is there anyway you could help me get specific requirments. Like the screen says tap space and a green bar appears?

Since there's already another more recent thread that asks the same question, I'm closing this thread.

Original thread: https://forums.rpgmakerweb.com/threads/need-help-with-button-mashing-event.117905/