MZ Using the wait command in a plugin

I have been trying to use the wait command for multiple things, but it has never worked for me as described in this spreadsheet made by many users

(it's the same one Archaeia has in his thread)


When I try to write
JavaScript:
this.wait
it doesn't work because it's undefined, the interpreter doesn't have the wait command in its method. I have tried everything that it's written there (pertaining the wait code) and it hasn't worked at all.
As of now, everything else in that documentation has worked until today, it's only that method that I cannot seem to make it work.

I am not sure what I am doing wrong.

I've tried using the method of setTimeout as a replacement, but for this particular situation that I am having using move commands, it doesn't work, as I will need to wait for the frames to finish.

Platform: Rpg maker mz
JS Plugin
Seems like I just decided to ignore the part that says (this only in a Script command) which is probably why it wasn't working.
part of it is also that the wait command doesn't work like most people assume.

there is a game loop that contains all ongoing processes from events to display updates to whatever.
each frame each of those processes is executed once/one step, then to the next process until the next loop.

the wait command now basically says "skip processing this object/process for x frames/loops".

That is why it reduces lag in a parallel process (the parallel is processed less often) and looks like a wait in a regular event.

In your plugin, the wait is only available if that plugin has an object or process that is inside the game loop itself. If you have such an updating object, the wait will work for it.
Or you can try to create one such object as a control/message point to pause some of your plugin functions by having that timerobject call the function after x loops.

(sorry, I can't give you the code because I only know the background, haven't dived into the real code for years)
Of course not, you're expecting to use a wait command outside the Game_Interpreter. The wait function is configured to only work for event commands (Game_Interpreter), you can't just use it outside of it and expect it to work without making your own wait function. And please do not use setTimeout, it would break everything especially when the game lags.

Literally, if you want to use wait, just make a variable that counts down/up until it is over. Put that in the game loop. That is how literally the wait command in the event command works. Even in the move route command, the wait function has a different way to set.

Speaking of the game loop. Do you know what a game loop is?
@TheoAllen: no. I do not.
If it helps all I want to do is to make a change in the movement animation when the character hits a key. In my case the code for the event movement is like this
Code:
...
 setTimeout(() => $gamePlayer.setDirection(4), 100);
    setTimeout(() => $gamePlayer.setDirection(6), 150);
    setTimeout(() => $gamePlayer.setDirection(8), 200);
    setTimeout(() => {
      $gamePlayer.setImage('actors', 0);
      //set direction to original direction
      $gamePlayer.setDirection(direction);
    }, 250);
...


@Andar: Thanks for the explanation.

Original thread: https://forums.rpgmakerweb.com/threads/using-the-wait-command-in-a-plugin.142057/