Button Mashing Event

Hello everyone,
I have some problem with eventing a button mash scene. For some reason, no matter how fast I press the button, the results are always success. What did I do wrong?
Thanks in advance!
Capture.PNG
you do increase the variable +1.

so to figure it out, set a console log or rather a warn.

console.warn("you clicked", $gameVariable.value(25), "x times")

or change warn to error (which I think it pop up on the on a window.
set both inside the success and on FAIL to see if it triggers.

what happens if you don't press OK?

also, you can also change that line to: Input.isTriggered("ok") instead
as if you use press (if can be hold down to speed it up to 9+.
👋 I would use this structure for the commands inside the loop:
  • If Self Switch A is ON (i.e. button was pressed down during previous check)
    • If [OK] is pressed
      • (Nothing.)
      Else
      • Turn OFF Self Switch A.
    Else (i.e. button was NOT pressed down during previous check)
    • If [OK] is pressed
      • +1 to Variable {Button Mash}
      • Turn ON Self Switch A
  • If Variable {Button Mash} > 9
    • Break Loop
  • Wait 1 frame
A couple of notes:
  1. There is a Wait 1 frame command at the end of the loop. This is to make sure it only checks once per frame, rather than as many times as possible. Very important!

  2. I've used a self-switch to remember whether the button was pressed last time it was checked. This lets us only increase the variable when the button is pressed now AND wasn't pressed last frame. I.e. the button has to be released between presses, and can't just be held down.
Also, if you use this variable for other events like this, remember to set it to 0 before starting the loop.
👋 I would use this structure for the commands inside the loop:
  • If Self Switch A is ON (i.e. button was pressed down during previous check)
    • If [OK] is pressed
      • (Nothing.)
      Else
      • Turn OFF Self Switch A.
    Else (i.e. button was NOT pressed down during previous check)
    • If [OK] is pressed
      • +1 to Variable {Button Mash}
      • Turn ON Self Switch A
  • If Variable {Button Mash} > 9
    • Break Loop
  • Wait 1 frame
A couple of notes:
  1. There is a Wait 1 frame command at the end of the loop. This is to make sure it only checks once per frame, rather than as many times as possible. Very important!

  2. I've used a self-switch to remember whether the button was pressed last time it was checked. This lets us only increase the variable when the button is pressed now AND wasn't pressed last frame. I.e. the button has to be released between presses, and can't just be held down.
Also, if you use this variable for other events like this, remember to set it to 0 before starting the loop.
Thanks for your help, but I was using a timer there as well because I wanted to have a game over if you don't press enough as well. Where do I fit that in the event?
It's just another way the loop can end, so you can just add another "if" branch to check the timer, i.e.
  • If Self Switch A is ON (i.e. button was pressed down during previous check)
    • If [OK] is pressed
      • (Nothing.)
      Else
      • Turn OFF Self Switch A.
    Else (i.e. button was NOT pressed down during previous check)
    • If [OK] is pressed
      • +1 to Variable {Button Mash}
      • Turn ON Self Switch A
  • If Variable {Button Mash} > 9
    • Break Loop (pass)
  • If Timer ≤ 0 min 0 sec
    • Break Loop (fail)
  • Wait 1 frame
Then, after the loop, you could distinguish pass/fail based on the value of the variable: if it's more than 9 then the loop ended because the button mash was successful, otherwise it ended because the timer ran out. E.g.
  • Loop
    ...
    Repeat Above
  • If Variable {Button Mash} > 9 (pass)
    • Erase Picture #2
    • Show Text: Gah!
    • ...etc
    Else (fail)
    • Flash Screen
    • Play SE
    • Game Over
Rather than checking if the button is pressed down, you should probably check if the button was triggered. Input.isPressed('ok') checks if the button is currently being held down, but
Input.isTriggered('ok') checks if the button is down this frame, but was up last frame. That way the player can't just keep holding the button, and you won't get it counting more than once if it just whizzes through the loop multiple times in a single button press. Just change your conditional branch to be
Script: Input.isTriggered('ok')
instead of
Button: [OK] is pressed down

Original thread: https://forums.rpgmakerweb.com/threads/button-mashing-event.179412/