[Bug] (Minor) Restore move route index skip

caethyril

^_^
Veteran
Joined
Feb 21, 2018
Messages
2,219
Reaction score
1,628
First Language
EN
Primarily Uses
RMMZ
:kaohi: I'll use these phrases:
  • "Passive route" = an event's autonomous movement route.
  • "Active route" = a forced move route; a move route applied via, for example, the Set Movement Route command.
User: @caethyril
Bug:
  • When an active move route ends, the passive route (if any) is restored. However, the passive route's index is immediately incremented, meaning that one move command is always skipped. This can result in unreliable behaviour.
How to replicate/demo
Code explanation
  • processMoveCommand is unconditionally followed by advanceMoveRouteIndex:
    JavaScript:
    Game_Character.prototype.updateRoutineMove = function() {
        if (this._waitCount > 0) {
            this._waitCount--;
        } else {
            this.setMovementSuccess(true);
            var command = this._moveRoute.list[this._moveRouteIndex];
            if (command) {
                this.processMoveCommand(command);
                this.advanceMoveRouteIndex();
            }
        }
    };
    
    Game_Character.prototype.advanceMoveRouteIndex = function() {
        var moveRoute = this._moveRoute;
        if (moveRoute && (this.isMovementSucceeded() || moveRoute.skippable)) {
            var numCommands = moveRoute.list.length - 1;
            this._moveRouteIndex++;
            if (moveRoute.repeat && this._moveRouteIndex >= numCommands) {
                this._moveRouteIndex = 0;
            }
        }
    };
    The memorize/restore routines simply take the current index value:
    JavaScript:
    Game_Character.prototype.memorizeMoveRoute = function() {
        this._originalMoveRoute       = this._moveRoute;
        this._originalMoveRouteIndex  = this._moveRouteIndex;
    };
    
    Game_Character.prototype.restoreMoveRoute = function() {
        this._moveRoute          = this._originalMoveRoute;
        this._moveRouteIndex     = this._originalMoveRouteIndex;
        this._originalMoveRoute  = null;
    };
    Thus when the passive route is restored, its index is effectively set to "original + 1". However, at that point the original index has not been processed, because it was replaced by the first command of the active route.
Two possible fixes
  1. Subtract one from the original move route index on memorisation:
    JavaScript:
    Game_Character.prototype.memorizeMoveRoute = function() {
        this._originalMoveRoute       = this._moveRoute;
        this._originalMoveRouteIndex  = this._moveRouteIndex - 1;  // <- edit 1 of 1
    };
  2. Alternatively, subtract one from the index on restore:
    JavaScript:
    Game_Character.prototype.restoreMoveRoute = function() {
        this._moveRoute          = this._originalMoveRoute;
        this._moveRouteIndex     = this._originalMoveRouteIndex - 1;  // <- edit 1 of 1
        this._originalMoveRoute  = null;
    };
It looks like this bug is also present in v0.9.5 of the RMMZ code (I don't think there's a forum for that yet, though). :kaoswt:
 

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Profile Posts

Sheila Nagase

same caption as before. :3
"Be as honest as you possibly can as often as you can. It makes your lies much easier to believe."
Each new game means new ways to survive and you need to adapt when you have 10 different stores with lots of items for your adventure
It took really long to gather the 4 siblings to make this pictur- where did the fourth one go!?

Forum statistics

Threads
107,373
Messages
1,029,186
Members
139,468
Latest member
Frostlord_Icy
Top