MZ Wait command in JavaScript

Hey guys. So I am working on a few of my own plugins that involve player and event movement and the Game_Player.prototype.triggerButtonAction function. I am having an issue where the player can spam the trigger button and I want to prevent that with a wait command. Essentially what I want is for the player to input the trigger button, then the wait command waits for a certain amount of frames so the player can't move or input the trigger button again until the statement is done. I tried using interpreter.wait(frames); from the MZ Script Calls in my code but was getting errors (I'm sure I was using it wrong). Was wondering if anyone could help with this. I've posted a snippet of the code for reference.
if ($gamePlayer.direction() === 2) { this.wait(60); event1.setDirection(2); $gamePlayer.setThrough(true); event1.moveStraight(2); event1.moveStraight(2); event1.moveStraight(2); event1.moveStraight(2); event1.moveStraight(2); for (const postEventId in postEvents) { const postEvent = postEvents[postEventId]; if (postEvent.event().name === postName) { const postEventX = postEvent.x; const postEventY = postEvent.y; if (event1X === postEventX && event1Y === postEventY) { $gamePlayer.moveStraight(2); $gamePlayer.moveStraight(2); $gamePlayer.moveStraight(2); $gamePlayer.moveStraight(2); } } } $gamePlayer.setThrough(false);

Thanks!
first thing you need to know is that technically there is no wait at all.

Everything in the game is processed in a game loop, and what the wait command really does is tell the engine "stop processing this object for x repeats of the main loop".

Second thing is that each parallel process and each movement route and so on get their own interpreter process for the loop - and the wait command always effects ONLY the process it is called from. Your "interpreter.wait" is probably missing the information which interpreter process should wait.
Are you trying to program event command "macros"? If so, you're probably going to have to get familiar with the gritty details of how the engine actually handles event commands. Have you tried doing this using common event(s) instead? Might be much easier that way.

this refers to the current scope, a.k.a. execution context. For example, in a Script command, this is a reference to the current event interpreter (a Game_Interpreter instance). That will not be true in all cases.

A Game_Interpreter checks wait time between commands. So it doesn't matter where you call wait or setWaitMode from, it can only apply after the current command (e.g. Script, or Plugin Command) has finished processing. And if that interpreter is not already running an event, then nothing will happen.

Also, multiple moveStraight commands in a row like that will teleport the character to the penultimate tile, then walk them smoothly to the final tile. To process it normally, you would build a move route and assign it to the character.
first thing you need to know is that technically there is no wait at all.

Everything in the game is processed in a game loop, and what the wait command really does is tell the engine "stop processing this object for x repeats of the main loop".

Second thing is that each parallel process and each movement route and so on get their own interpreter process for the loop - and the wait command always effects ONLY the process it is called from. Your "interpreter.wait" is probably missing the information which interpreter process should wait.
Are you trying to program event command "macros"? If so, you're probably going to have to get familiar with the gritty details of how the engine actually handles event commands. Have you tried doing this using common event(s) instead? Might be much easier that way.

this refers to the current scope, a.k.a. execution context. For example, in a Script command, this is a reference to the current event interpreter (a Game_Interpreter instance). That will not be true in all cases.

A Game_Interpreter checks wait time between commands. So it doesn't matter where you call wait or setWaitMode from, it can only apply after the current command (e.g. Script, or Plugin Command) has finished processing. And if that interpreter is not already running an event, then nothing will happen.

Also, multiple moveStraight commands in a row like that will teleport the character to the penultimate tile, then walk them smoothly to the final tile. To process it normally, you would build a move route and assign it to the character.
Damn, thanks for explaining this guys. I could use common events but my plan was to practice plugin development.

Are you trying to program event command "macros"?
I'm pretty much trying to make a hookshot event which I know how to do with events but wanted to try doing it with plugin development. I think MOGhunter had a working one for RPG Maker MV.


Also, multiple moveStraight commands in a row like that will teleport the character to the penultimate tile, then walk them smoothly to the final tile. To process it normally, you would build a move route and assign it to the character.
Yes, I had already witnessed this first hand lol.

Original thread: https://forums.rpgmakerweb.com/threads/wait-command-in-javascript.160079/