Timed common event

Hi! I'm having problems trying to make some changes to a button mash event by Caz (https://itch.io/queue/c/1353582/cookie-cutter-mz-rpg-maker-mz-project-templates?game_id=979800).
Here are some snippets of the parts I need to edit. I want to make it so the player has 10 seconds to complete the button mash event, if not the event stops and a defeat event starts. The event is a common one if that might help 🙂. Thank you so so much! 🙂
1720768621254.png
1720768639138.png
You would have to implement a timer logic to this structure.
You could try something like this :

Code:
◆ Control Switches: #0208 Begin button meshing = ON
    ◆ Control Variables: #0235 Button Mesh Width = 0
◆ Control Variables: #0236 Timer = 0
◆ Loop
  ◆ Control Variables: #0236 Timer += 1
  ◆ If: Button [OK] is pressed
    ◆ Control Variables: #0235 Button Mesh Width += 2
    ◆ Show Picture: #3, BME-PressOK2, Upper Left (360,430), (100%,100%), 255, Normal
    ◆ Wait: 3 frames
    ◆ Control Variables: #0236 Timer += 3
    ◆ Show Picture: #3, BME-PressOK1, Upper Left (360,430), (100%,100%), 255, Normal
  ◆ End

  ◆ If: Button Mesh Width ≥ 100
    ◆ Control Switches: #0208 Begin button meshing = OFF
    ◆ Show Text: "Event Succes"
    ◆ Break Loop
  ◆ End

  ◆ If: Control Variables: #0236 Timer ≥ 600
    ◆ Control Switches: #0208 Begin button meshing = OFF
    ◆ Show Text: "Defeat Event"
    ◆ Break Loop
  ◆ End

  ◆ Wait: 1 frame
◆ Repeat Above

◆ If: Button Mesh Width ≤ 0
  ◆ Control Variables: #0235 Button Mesh Width = 0
◆ End

◆ If: Button Mesh Width ≥ 100
  ◆ Control Variables: #0235 Button Mesh Width = 100
◆ End

Did not test, but should do the job
You can change ◆ Show Text: "Defeat Event" by anything you want it to be for "Defeat", an event call, or anything else
You won't have to reset the timer, as every time this event starts the timer will be set to 0.
But think about resetting the Button Mesh Width value.

If you are at ease with javascript and want a more accurate timing, you could use something like this :

JavaScript:
//Before the loop begins, set the current time
$gameVariables.setValue(237, Date.now())
// 237 would be the start of the timer

//Before checking for the Mesh value and Timer value, set the elapsed time
$gameVariables.setValue(236, (Date.now() - $gameVariables.value(237)) / 1000)
// 236 would be the elapsed time based on the start timer

Then, instead of checking for a value of 600 (600 frames = roughly 10 seconds) you can check for a value of 10 or more (current time - start time, which will be a float)
You would have to implement a timer logic to this structure.
You could try something like this :

Code:
◆ Control Switches: #0208 Begin button meshing = ON
    ◆ Control Variables: #0235 Button Mesh Width = 0
◆ Control Variables: #0236 Timer = 0
◆ Loop
  ◆ Control Variables: #0236 Timer += 1
  ◆ If: Button [OK] is pressed
    ◆ Control Variables: #0235 Button Mesh Width += 2
    ◆ Show Picture: #3, BME-PressOK2, Upper Left (360,430), (100%,100%), 255, Normal
    ◆ Wait: 3 frames
    ◆ Control Variables: #0236 Timer += 3
    ◆ Show Picture: #3, BME-PressOK1, Upper Left (360,430), (100%,100%), 255, Normal
  ◆ End

  ◆ If: Button Mesh Width ≥ 100
    ◆ Control Switches: #0208 Begin button meshing = OFF
    ◆ Show Text: "Event Succes"
    ◆ Break Loop
  ◆ End

  ◆ If: Control Variables: #0236 Timer ≥ 600
    ◆ Control Switches: #0208 Begin button meshing = OFF
    ◆ Show Text: "Defeat Event"
    ◆ Break Loop
  ◆ End

  ◆ Wait: 1 frame
◆ Repeat Above

◆ If: Button Mesh Width ≤ 0
  ◆ Control Variables: #0235 Button Mesh Width = 0
◆ End

◆ If: Button Mesh Width ≥ 100
  ◆ Control Variables: #0235 Button Mesh Width = 100
◆ End

Did not test, but should do the job
You can change ◆ Show Text: "Defeat Event" by anything you want it to be for "Defeat", an event call, or anything else
You won't have to reset the timer, as every time this event starts the timer will be set to 0.
But think about resetting the Button Mesh Width value.

If you are at ease with javascript and want a more accurate timing, you could use something like this :

JavaScript:
//Before the loop begins, set the current time
$gameVariables.setValue(237, Date.now())
// 237 would be the start of the timer

//Before checking for the Mesh value and Timer value, set the elapsed time
$gameVariables.setValue(236, (Date.now() - $gameVariables.value(237)) / 1000)
// 236 would be the elapsed time based on the start timer

Then, instead of checking for a value of 600 (600 frames = roughly 10 seconds) you can check for a value of 10 or more (current time - start time, which will be a float)
Hi! Thank you so much for your reply! 🙂
Edit: Thank you so so much it works!

Original thread: https://forums.rpgmakerweb.com/threads/timed-common-event.170218/