RMMV Calling a move route script from a move route script button

stramin

Veteran
Veteran
Joined
Nov 4, 2012
Messages
240
Reaction score
102
First Language
spanish
Primarily Uses
N/A
Hi hi!

I have this function

JavaScript:
var CropGrowth = function (evid) {
     var tur = { code: 36, parameters: [] };
     var fix = { code: 35, parameters: [] };
     var end = { code: 0, parameters: [] };
         var moveRoute={
            list:[tur,{code:19,parameters:[]},fix,end], // face up
            repeat:false,
            skippable:false,
            wait:false
        };
        $gameMap.event(evid).forceMoveRoute(moveRoute);
};

It makes the event id `evid` to face up.

It works when I call it from a script, but I also need to call it from a movement route script, and when I do, it fails silently (with no errors).

I call it this way on the move route:
  • CropGrowth(this._eventId);
I tried these ways to force the move route:
  • $gameMap.event(evid).forceMoveRoute(moveRoute);
  • $gameMap._interpreter.event(evid).forceMoveRoute(moveRoute);
  • this.forceMoveRoute(moveRoute);
Thank you in advance!
 
Last edited:

Rugman

Veteran
Veteran
Joined
Jun 11, 2020
Messages
290
Reaction score
82
First Language
English
Primarily Uses
RMMV
Why did you write a function for that? Can you not make your event face up with the default commands?
 

Shaz

Global Moderators
Global Mod
Joined
Mar 2, 2012
Messages
42,811
Reaction score
14,977
First Language
English
Primarily Uses
RMMV
Applying a move route from within a move route script is probably questionable. What does the rest of the original move route look like?

I don't see any glaring issues apart from that.

I would try adding $gameMap.event(evid)._moveRouteIndex = -1 right after the forceMoveRoute, just so if returns from this function and wants to advance the index, it advances it to 0 rather than the enxt item in your original move route. I'd also add some console.log output in your function to make sure it's running it. And if all else fails, I'd add a breakpoint at the beginning of processMoveCommand so I can see exactly what it's trying to run.
 

stramin

Veteran
Veteran
Joined
Nov 4, 2012
Messages
240
Reaction score
102
First Language
spanish
Primarily Uses
N/A
Why did you write a function for that? Can you not make your event face up with the default commands?
Short answer: I have an event which shows a text when the player touches it and also checks a variable every 10 seconds using a custom route, this is the only way I know I can make an event being triggered by touch and parallel event.

Long answer: I have a crop system where the player can "plant" a seed on some areas, I use Yanfly Event copier for this, the player can select a seed, and it begins to "grow", the plant can take long time, and the player can left the map and come back to check how the plant is, the player can touch the plant to get the current status, to do it the event checks the CropGrowth() function to calculate the elapsed time and returns a variable to show it on the message text, this function also makes the plant grow (changing where it is facing: down (small leaves), left (mature), right (fruits ready to harvest) and up (dead)), this works fine but it forces the player to touch the plant in order to make it grow and I need they grow with no player touch, so, I made the move route, it repeats the same function every 10 seconds to check the self variable and make it grow, but for some reason it doesn't work here.
Applying a move route from within a move route script is probably questionable. What does the rest of the original move route look like?

I don't see any glaring issues apart from that.

I would try adding $gameMap.event(evid)._moveRouteIndex = -1 right after the forceMoveRoute, just so if returns from this function and wants to advance the index, it advances it to 0 rather than the enxt item in your original move route. I'd also add some console.log output in your function to make sure it's running it. And if all else fails, I'd add a breakpoint at the beginning of processMoveCommand so I can see exactly what it's trying to run.
The move route is this:
1617351417919.png

I added $gameMap.event(evid)._moveRouteIndex = -1, but it didn't work,

I added a console.log("run"), it seems like it is running normally:
1617351276056.png

With this console log, I found something relevant, the forceMoveRoute do WORKS on the move route and makes it face up as expected when the variable changes, the problem is when I touch the event, after I touch it, the forceMoveRoute stop working for the movement route only (it works if i touch it again).

the console logs continues showing the "run" text after touching it, so, the function still being call, but is not changing the route anymore... or is not turning off the fixed direction... i will make more tests...

--------- EDIT ----------

SOLVED!!

forceMoveRoute, begun to work cause the _moveRouteIndex=-1, it WASN'T working before,
but when I touch the event there is no move route and moving the index back causes the forceMoveRoute stopped working...

SO, what I did is to say the function when we are in the movement route adding an argument "isMoveRoute":


JavaScript:
var CropGrowth = function (evid,isMoveRoute) {
    console.log("run");

    var tur = { code: 36, parameters: [] };
    var fix = { code: 35, parameters: [] };
    var end = { code: 0, parameters: [] };
    var moveRoute={
        list:[tur,{code:$gameVariables.value(2),parameters:[]},fix,end], // face up
        repeat:false,
        skippable:false,
        wait:false
    };
    $gameMap.event(evid).forceMoveRoute(moveRoute);
    if(isMoveRoute) $gameMap.event(evid)._moveRouteIndex = -1;
}

then I call it this way from the move route:
  • CropGrowth(this._eventId,1);
and this way from the event:
  • CropGrowth(this._eventId,0);
And works perfectly!

Thank you so much Shaz, the moveRouteIndex was the key.
 
Last edited:

Shaz

Global Moderators
Global Mod
Joined
Mar 2, 2012
Messages
42,811
Reaction score
14,977
First Language
English
Primarily Uses
RMMV
ooh, that sounds wayyyy too painful - please try this instead.

 

stramin

Veteran
Veteran
Joined
Nov 4, 2012
Messages
240
Reaction score
102
First Language
spanish
Primarily Uses
N/A
That looks useful, I have some questions, but they are not related to this topic, so I going to ask them there.

Thank you~~~
 

Shaz

Global Moderators
Global Mod
Joined
Mar 2, 2012
Messages
42,811
Reaction score
14,977
First Language
English
Primarily Uses
RMMV
Just going back to your screenshot ... that 600 frame wait would never be run, because you have it in the move route, after the command that's going to replace the move route with a new one. If you want the 600 frame wait, then it should either be at the start of the original move route (nothing should come after the call to the function), or it should be somewhere in the new move route.

But I think the plugin would be better in this case.
 

stramin

Veteran
Veteran
Joined
Nov 4, 2012
Messages
240
Reaction score
102
First Language
spanish
Primarily Uses
N/A
You mean, doing this?
1617408421836.png

I will try, but it is working, it do wait for 10 seconds and every crop has its own sync, I made a video for it :kaojoy:

 

Latest Threads

Latest Posts

Latest Profile Posts

So many ideas, so little energy.
SA57Face.pngSA57_IDLE.gifThis is just a "Chinese opera actor" who is totally not a serial killer. Now, we just need to clean up a pile of dead bodies found in his backyard. :kaojoy:
E7DsT3VXsAInVpu

working on my avatar, because i couldn't stand looking at it anymore :D
still not finished though...
alpacaraptors = love!

Forum statistics

Threads
113,585
Messages
1,076,019
Members
147,574
Latest member
Phongsasuke
Top