Wait for movement completion?

Hello!
I'm making an event to allow me to dynamically choose which event in a map will move without making a too convoluted event page, so i created this:
Spoiler: script
$gameMap.event(i).moveStraight(direction);

//Where "i" is the event that will move, and "direction" is where it will be headed to.

But then i noticed that using a script the game will not wait for it to end before progressing to the next command, so I found an old thread where a guy had the same problem, but with message texts, and they advised him to use this method:

Spoiler: code
Game_Interpreter.prototype.updateWaitMode = function() {
var waiting = false;
switch (this._waitMode) {
case 'message':
waiting = $gameMessage.isBusy();
break;
case 'transfer':
waiting = $gamePlayer.isTransferring();
break;
case 'scroll':
waiting = $gameMap.isScrolling();
break;
case 'route':
waiting = this._character.isMoveRouteForcing();
break;
case 'animation':
waiting = this._character.isAnimationPlaying();
break;
case 'balloon':
waiting = this._character.isBalloonPlaying();
break;
case 'gather':
waiting = $gamePlayer.areFollowersGathering();
break;
case 'action':
waiting = BattleManager.isActionForced();
break;
case 'video':
waiting = Graphics.isVideoPlaying();
break;
case 'image':
waiting = !ImageManager.isReady();
break;
}
if (!waiting) {
this._waitMode = '';
}
return waiting;
};

I decided to try it, using the 'route' case, and wrote the script this way:
Spoiler: code
$gameMap.event(i).moveStraight(direction);
this.setWaitMode('route');


Unfortunately it didn't work, giving me instead this error:

Schermata-2019-07-30-alle-17-48-22.png


What does it mean? Does it mean that i'm using the wrong case? Or I wrote the code wrong?
Thanks in advance.
It means the event has no move route. The "route" case is for move route.
moveStraight does not set the event's move route in any way, it will just move the event one square forward. Setting a move route is more complex than that. I recommend you to search for RPG maker MV script call list, there's a sheet that might help you setup a move route.
I see ^^"
Thank you very much!

EDIT: I'm now having another problem ^^"
I set up the route this way:

Spoiler: code
var event = $gameVariables.value(36); var direction = $gameVariables.value(93); var steps = $gameVariables.value(87);

var cMove = { code: direction, parameters: [] };
var cEnd = { code: Game_Character.ROUTE_END, parameters: [] };
var cList = [cMove, cEnd];

var moveRoute = {list: cList, repeat: false, skippable: false, wait: true};

do
{
$gameMap.event(event).forceMoveRoute(moveRoute);
this.setWaitMode('route');
steps -= 1;
}
while(steps > 0);

And it seems to work, but the "this.setWaitMode('route');" method still gives me the same in-game error.

Original thread: https://forums.rpgmakerweb.com/threads/wait-for-movement-completion.111625/