Attempting to move events via script

Hi! I'm new to RPGMV and JS but not to programming in general - lots of experience in Python and other languages. Right now I'm trying to make a script that controls the movement of several events in a city - namely, Cars. I have several of the basics hammered out (how to make them move offscreen, how the sprites are going to look, etc) but plugging it all into RPGMV is giving me some trouble.

To familiarize myself first I'm just trying to get the script to move the sprite across the screen a small distance.

 

var CarMove = Carmove || {};


CarMove.parameters = PluginManager.parameters('CarMove');


for(var x = 0; x < 10; x++){
    gameMap.event(022).moveStraight(2);
}


This is my attempt so far and it does nothing. I'm attemping to move event #022 down a few steps. Could someone explain where I'm going wrong? I apologize in advance if this is a pitiful question.
You have to give the event a proper move route.  This causes it to execute a movement and wait for it to be complete before it does the next one.


Also, you've got some syntax errors / typos in there.


$gameMap, not gameMap


event(22), not event(022)


but at best, I'd expect it to move once, because you're not waiting for the movement to complete.


This is how you create a move route via script in Ace:





You would need to figure out the MV equivalent.  A good starting point is to create the move route in an event, save it, then go take a look at the Map###.json file to see what the commands and properties are, and then use script to recreate it.


tbh I think doing it via script is more trouble than its worth, and unless it's exactly the same move route applied to a large number of events, I'd just event it.  You can use the Autonomous Movement set to Custom (to the right of the event graphic) to set up automatic movement.  You don't need to set the event trigger to Parallel Process for this to work - autonomous movement is independent of the trigger, so just leave it as Action Button (or Event Touch if you want the cars to be able to hit the player)

Original thread: https://forums.rpgmakerweb.com/threads/attempting-to-move-events-via-script.72451/