MZ How to insert a Wait in this for loop script?

I have tested this script and know that is works.

for (var i =x; i<y+1; i++){

$gameScreen.erasePicture(i); }

Where X is the starting Picture and Y is the Ending Picture.

However, I want to erase this range of pictures with a Wait of 10 frames between each erasure.

I have tried inserting a bunch of things that I tried to look up. Like this.wait() or sleep() or setTimeout function(), but it doesn't work. Probably because I don't know how to insert it properly in the script with the correct syntax. Or maybe I am using the wrong Java Script.

Could someone show how to insert a 10 frame wait in this loop so there is a 10 frame wait between erasing each picture in the range?

Thanks in advance!
The interpreter's wait() function only works between event commands. Your entire Script is one event command, so that can't work.

The best way to do this is to not script it all. Use event commands.
Control Variables -> 69 = 1
Loop
- Script $gameScreen.erasePicture($gameVariables.value(69));
- Control Variables -> 69 + 1
- Conditional Branch -> Variable 69 == 10
-- Break Loop
- Wait 10

Obviously adjusting the variable ID and the starting and end values to whatever you need.
You can not put wait in the same script call slot, unfortunately (I've said this in RPG Maker peeves thread). The script inside the same script call is executed at the same time. So you have to make a workaround.

For example, you could use the default RPG Maker looping.
Well, crap! Here I was trying to get better at using scripts and this actually calls for basic Event commands. Go figure.

Thanks!
Yeah - doing things efficiently in RPG Maker requires you to know when it's worthwhile to use code vs. an event command.
This thread is being closed due to being solved. If you need it reopened, report it to let us know why. Thank you!

Original thread: https://forums.rpgmakerweb.com/threads/how-to-insert-a-wait-in-this-for-loop-script.165202/