Event Movement Timing

Hi, I'm trying to have an event move, and then run a script based on its new position, which can tell it to move again... and so on...


I'm having problems though because I don't know how to tell an event to run a script after it has moved.  Instead it tends queues up the movement, and then runs the script over and over again, locking up the game.


I've been digging through the rpg_objects code for hours, but I think I'm just missing something simple.


Any help would be desperately appreciated!
Are you doing this through event commands or trying to modify scripts to do it?  Please show a screenshot of what you've got so far as your description doesn't really give us much to go on.


Could be as simple as setting the movement route to 'wait for completion' before running the script.
Hi Shaz,


Thanks for replying so fast.  I've been trying both.


Right now, I have a command, telling my event to move, and then an script deciding where it should move from there.


Set Movement Route : This Event (Wait)


 :<>Move Right.


Which works.


Then I wrote a script that tells it where to move next, based on its surroundings.


That also works.


My problem is I want to run the script again, after the event gets there.  And it locks up.


I've set "wait for completion" in both my event command and my script.  But the code still locks up.  I guess because my code doesn't know how to wait, even though the event knows to wait...  Or something?  I don't know...
Can you please show a screenshot?  And if you wrote a script, include that too (in spoilers and code tags)
It sounds as if you made the script call at the wrong position in the event code - that is why we need a screenshot to see exactly what you placed where.
Hi-- I woke up this morning determined and finally got it.  Sorry I couldn't explain better.


I was just trying to make a train move on some tracks.  Which is all script right now, and not any kind of event (although I tried using events).


What I needed to do was change Game_Event.prototype.update() 


Which is the code that calls all the movement codes.  When I added my little script to that, it worked fine.


If this continues to work fine, I'll try to build a plugin.


Thanks again for your time.
 

Spoiler
Code:
INT.Game_Event_update = Game_Event.prototype.update;
Game_Event.prototype.update = function() {
    INT.Game_Event_update.call(this);
    if (this._eventData.note=="train" && DataManager.moving==true) this.CheckTracks();
};

Game_Event.prototype.CheckTracks = function() {        
        var idlist = $gameMap.eventsXy(this.x, this.y);
            for (var i=0; i<idlist.length; i++) {
                if (idlist[i]._eventData.note=="track") {
                    var track= idlist[i]._eventData.name;
                    var d1= ""
                    var d2= ""
                    var mine_dir=this.direction()
                    
                    for (var j = 0; j< track.length; j++) {
                        d1=GetDir(track[j]);
                        j++;
                        d2=GetDir(track[j]); 
                       
                        if (10 - d1 == this.direction())  {
                            this.setDirection(d2)
                            this.MoveForward()
                            
                        }
                        if (10 - d2 == this.direction())  {
                            /*this.moveStraight(GetDir(d1));*/
                            this.setDirection(d1)
                            this.MoveForward()                                        
                        }
                    }
                }
            }
}
    

        
this_event.moveForward();
        this.forceMoveRoute({
            list:
            [
            {
            code: 12,
            indent: null,
            parameters:[]
            }
            ,{
            code: 0,
            indent: null,
            parameters:[]
            }
            ]
            ,
            repeat:false,
            skippable:false,
            wait:true
            })
    }



function GetDir(dir) {
if (dir == "W") return 4
if (dir == "N") return 8
if (dir == "S") return 2
if (dir == "E") return 6
}
@Internetomancer and where is the screenshot of the event?


And by the way, why a script? why not simply use the existing functions provided by the events?
There's not much of an event anymore...


The script is so the event can interact with other events.  In this case a train interacting with train tracks.  There's probably some easier ways to do it, but I don't know any method using just events.

screen.png
I suggest you check the area called "autonomous movement" between the image and the content. Those movement controls are independent of the event content - usually that allows a villager to move around while still starting a conversation on action button.


Interaction between events should always be controlled and checked from the outside, not from the events themselves. There are a lot of reasons for that (including to prevent mistiming), some of them you can read about in the bughunting tutorial I wrote (link in my signature).


There are different ways to control an events movement, and you need to use them all depending on what exactly the specific case is - for example there are scripts that place barriers only for events on the map, and you can let the event move randomly within those areas while the player can still go everywhere.


Or you can preprogram the move routes, or use a parallel process to check for positions, or several other options.


Which one is best depends on the exact situation - a tracked train would use a different method than a randomly wandering animal for optimal effects

Original thread: https://forums.rpgmakerweb.com/threads/event-movement-timing.63008/