Moving Event via script call problem

Hello!


I am trying to move an event (ID 18 in this case) via script call, and I'm trying to move it exactly three times. My code looks like this:


var i = 3;
while (i > 0)
{
$gameMap.event(18).moveRandom();
i--;
}


The event jumps around weirdly instead of moving properly when I do this.


Example:


movement.gif


Is it because the script is not waiting for the movement to finish? How do I get it to wait?


If I use a for loop instead, the event only moves once instead of three times.
im confused, why not just do a movement route?


edit: cause you want it random..i see
I'm doing it with a script call because I want to replace the ID of the event, which I am hardcoding for now, with a variable later.

Original thread: https://forums.rpgmakerweb.com/threads/moving-event-via-script-call-problem.70442/