MZ What's the best way to call Set Movement Route via script?

(I couldn't find a post about using Set Movement Route in script... did see a few references for the parameters, but not how to actually call the function.)

I want to change an event's image and direction based off variables using Set Movement Route. I figured it would be easier to do via a plugin command rather than writing a lot of conditional statements in the event editor.

I found the Game Interpreter's command205 (Set Movement Route) in rmmz_objects.js and figured out how to properly set the function parameters, but I'm not sure how to actually call the Set Movement Route function. I'm not sure what this means in the code, but I get the feeling that simply copying the function's code to my script wouldn't work.

Is there a better way to call Set Movement Route in scripts? If not, how do you call this function? Any help would be appreciated! 😅

JavaScript:
// Set Movement Route
Game_Interpreter.prototype.command205 = function(params) {
    $gameMap.refreshIfNeeded();
    this._characterId = params[0];
    const character = this.character(this._characterId);
    if (character) {
        character.forceMoveRoute(params[1]);
        if (params[1].wait) {
            this.setWaitMode("route");
        }
    }
    return true;
};
This may help you.
I want to change an event's image and direction based off variables using Set Movement Route
don't - if you want to drive from Berlin to Paris, you don't drive to Moscow first, because that would be going the wrong way.

"Set move route" is a command that creates an independent game loop object, that then handles the movement on it's own. So if you want to create a move route from script, you better create that game loop object directly without going through the interpreter. That is described in the link given above.

However if you want to change an event's image then it would again be easier to change that directly - because in script you have direct access to the event properties and no need to go through set move route at all.

That said, both ways are complex due to the need of setting a lot of data.

In fact, most people decide to go an entire different route: the clone event route.
There are plugins for that, and they worki by basically creating every possible event in a master map that is never played on, and copy the needed event to whereever on the current map it is needed.
That is because using the editor to create events or events with moveroutes is easier than handling everything with script commands.
and as a result there are already several clone event or copy event plugins available.

Original thread: https://forums.rpgmakerweb.com/threads/whats-the-best-way-to-call-set-movement-route-via-script.172625/