Use wait in script

So I've tried to make it work with the below:
https://forums.rpgmakerweb.com/index.php?threads/using-wait-script-call.48288/
1625162626988.png


However I can't get it to work.

I want to use it in a loop for fading.

Psuedocode:
JavaScript:
for (x=0; x < 255, x+17) { //Every 1/4 seconds increase x by 17 to a maximum of 255(100% opacity)
picture.opacity(x)
this.wait(15); //1/4 of a second
}

How do I make a script wait?

Best regards,
Bishiba
Try this one:
Code:
await new Promise(resolve => setTimeout(resolve, x));

In place of x type a number, where 1000 will be one second.
I can't answer your original question as to the how, but I can give you the basics of what you most likely are missing.

There is a main game loop in the engine, that processes each contained object once per frame/per loop. The contained objects would be parallel events, active events, autonomous movements, display updates, plugin functions that added themselves there and so on.

And a lot of people have a misconception of what the wait command does. The only thing the wait does is tell the game loop "skip processing this object for x frames" (or "skip processing until that other object reports complete" in some rarer cases).

So the wait command alone does nothing unless the object it is called upon is part of the main game loop - and even then it only gives control info to the control of the main game loop, it does nothing directly.

so for your pseudocode to work, it cannot stand on its own - it has to be added to the update cycle of the main game loop.
And I'm not current enough in the engine code to tell you how to do that, but I know that the code will probably have to look very differently to do that.
Take a look at my SFG_Wait plugin (from the link in my signature). Even if it doesn't already do exactly what you want, it does show you generally how to make a custom wait condition.

Original thread: https://forums.rpgmakerweb.com/threads/use-wait-in-script.137990/