Keep pressing button for event?

Hi, I'm creating a "killswitch" in my game main menu to delete all save files, and the way I want to do it is by pressing Shift or any key for a number of seconds, and then an event starts asking for that choice.

How would you do that (I'm talking about the "Keep pressing Shift for X seconds"?


I'll be using the Button Common Events plugin if that matters.
parallel process with conditional branch "button pressed" counting up if pressed and set to zero if not pressed.
then check if the counting up reaches the required number of frames.
parallel process with conditional branch "button pressed" counting up if pressed and set to zero if not pressed.
then check if the counting up reaches the required number of frames.

I know I have to do something with the Conditional Branch - if X button is pressed, but I get lost after that, can you give me more help about it?
you need a variable to store the time.
both branches of the condition needs one control variable command - in the true case (button is pressed) this command needs to add one to the selected variable, in the false branch it needs to set the variable to zero.

then you need a second conditional branch in the true branch for checking the variable after one is added - if the number of frames now exceeds the time you want as trigger, do that. otherwise continue the parallel to count more time.
I did it!

I created a conditional branch where you press Shift, it adds +1 to a variable and waits 60 frames, then it opens a new conditional with the same instruction and does the same, but it has an "Else" where if it's not pressed, it resets the variable to 0!

And of course, another Event to detect when the variable is = 4, so in this case you'll have to keep pressing Shift for 4 seconds so you can pop whatever event you have in mind, for me it'll be opening a new option to delete all savefiles!

This should work for other purposes, like stepping on a place for too long, puzzles, etc, etc.

Killswitch to Delete files.png
Your method currently checks every second (4 times total) whether the Shift button is pressed down rather than checking if the Shift button has been pressed for 4 seconds.

It may not seem like a big difference, but the better solution as suggested by Andar is both simpler and more precise, something like this:

Code:
If: Button Shift is Pressed Down
    Control Variables: #0018 += 1
Else:
    Control Variables: #0018 = 0

Comment: 4 seconds is 240 frames
If: Variable #0018 == 240
    Do something
Your method currently checks every second (4 times total) whether the Shift button is pressed down rather than checking if the Shift button has been pressed for 4 seconds.

It may not seem like a big difference, but the better solution as suggested by Andar is both simpler and more precise, something like this:

Code:
If: Button Shift is Pressed Down
    Control Variables: #0018 += 1
Else:
    Control Variables: #0018 = 0

Comment: 4 seconds is 240 frames
If: Variable #0018 == 240
    Do something


Ahh that should work too! I guess I'll use the one you showed me, never thought about that approach!

Original thread: https://forums.rpgmakerweb.com/threads/keep-pressing-button-for-event.102656/