MV "Maximum call stack size exceeded"

hello.

I got a problom.
I made two plugin for test.

first plugin is

Code:
var _Game_Interpreter_pluginCommand =
Game_Interpreter.prototype.pluginCommand;
Game_Interpreter.prototype.pluginCommand = function(command, args) {
_Game_Interpreter_pluginCommand.call(this, command, args);
if(command == 'skillHandler'){
    $gameMessage.add('skill plugin test')
}


and this is second

Code:
Game_Actor.prototype.hasLeveledUp = function () {
 
    if(this._previousLevel == undefined){
    this._previousLevel = this._level;
    return false;
    }
    if (this._previousLevel != this._level) {
    this._previousLevel = this._level;
    return true;
    }
    return false;
    }


var _Game_Interpreter_pluginCommand =
    Game_Interpreter.prototype.pluginCommand;
Game_Interpreter.prototype.pluginCommand = function(command, args) {
_Game_Interpreter_pluginCommand.call(this, command, args);
if(command === 'evol'){
    $gameMessage.add('evolution plugin test')
}

I just made it for test.

and this is mv scene

1674217229280.png



I want make some event on level up.

so I made hasLeveledUp() function.

and when hasLeveledUp I want use some plugin.

but after I use it, it show up RangeError.

I can't understand why it happen.

If I write long code, it can be. but, I write just message.

last, this is my console.

1674217547385.png


if loop was problom, why it happen? it loop until only party size.

thank you for help me.

=====================================================================

I changed mv contents like this.
1674218039123.png


loop was not a problem.

I can't resolve it...help me plz...
The first plugin stores the original method in a global variable named _Game_Interpreter_pluginCommand. Then it calls whatever is stored in that variable when Game_Interpreter.prototype.pluginCommand is called.

The second plugin stores that method, modified by the first plugin, in that variable. This creates a loop, because _Game_Interpreter_pluginCommand now calls itself.

To fix this, you can create a local scope, e.g. using an IIFE:
JavaScript:
(function() {
    var _Game_Interpreter_pluginCommand =
    Game_Interpreter.prototype.pluginCommand;
    Game_Interpreter.prototype.pluginCommand = function(command, args) {
        _Game_Interpreter_pluginCommand.call(this, command, args);
        if (command == 'skillHandler'){
            $gameMessage.add('skill plugin test')
        }
    }  // added
})();
JavaScript:
Game_Actor.prototype.hasLeveledUp = function () {
   
    if (this._previousLevel == undefined){
        this._previousLevel = this._level;
        return false;
    }
    if (this._previousLevel != this._level) {
        this._previousLevel = this._level;
        return true;
    }
    return false;
}

(function() {
    var _Game_Interpreter_pluginCommand =
        Game_Interpreter.prototype.pluginCommand;
    Game_Interpreter.prototype.pluginCommand = function(command, args) {
    _Game_Interpreter_pluginCommand.call(this, command, args);
    if(command === 'evol'){
        $gameMessage.add('evolution plugin test')
    }
})();
This way, each var won't be seen outside its (function() { ... })(), so you can use the same name in each scope with no problems. 👋

The Game_Actor stuff for the second plugin doesn't have to be inside the IIFE, because it's just directly defining a property on an existing global object.

[Edit: added missing } for code of plugin 1.]
The first plugin stores the original method in a global variable named _Game_Interpreter_pluginCommand. Then it calls whatever is stored in that variable when Game_Interpreter.prototype.pluginCommand is called.

The second plugin stores that method, modified by the first plugin, in that variable. This creates a loop, because _Game_Interpreter_pluginCommand now calls itself.

IIFE:
JavaScript:
(function() {
    var _Game_Interpreter_pluginCommand =
    Game_Interpreter.prototype.pluginCommand;
    Game_Interpreter.prototype.pluginCommand = function(command, args) {
    _Game_Interpreter_pluginCommand.call(this, command, args);
    if(command == 'skillHandler'){
        $gameMessage.add('skill plugin test')
    }
})();
JavaScript:
Game_Actor.prototype.hasLeveledUp = function () {
  
    if (this._previousLevel == undefined){
        this._previousLevel = this._level;
        return false;
    }
    if (this._previousLevel != this._level) {
        this._previousLevel = this._level;
        return true;
    }
    return false;
}

(function() {
    var _Game_Interpreter_pluginCommand =
        Game_Interpreter.prototype.pluginCommand;
    Game_Interpreter.prototype.pluginCommand = function(command, args) {
    _Game_Interpreter_pluginCommand.call(this, command, args);
    if(command === 'evol'){
        $gameMessage.add('evolution plugin test')
    }
})();
This way, each var won't be seen outside its (function() { ... })(), so you can use the same name in each scope with no problems. 👋

The Game_Actor stuff for the second plugin doesn't have to be inside the IIFE, because it's just directly defining a property on an existing global object.
Oh my god...
I made a big mistake...
thank you...I just copied first code in second...so variables was same name..
it was so easy to find...oh...you are so genius...thank you.... XD
You're welcome! 👋

Alternatively you can define your stuff on a namespace, e.g.
  • MyPlugins.Plugin1._Game_Interpreter_pluginCommand
  • MyPlugins.Plugin2._Game_Interpreter_pluginCommand
That allows you to reference one plugin's variables from anywhere in the game, which can be useful if someone wants to write an extension/add-on for one of your plugins.
You're welcome! 👋

Alternatively you can define your stuff on a namespace, e.g.
  • MyStuff.Plugin1._Game_Interpreter_pluginCommand
  • MyStuff.Plugin2._Game_Interpreter_pluginCommand
That allows you to reference one plugin's variables from anywhere in the game, which can be useful if someone wants to write an extension/add-on for one of your plugins.
This is how I do it. All my plugins use a TLB object with an object property unique to the plugin where I store aliases and parameters.

Original thread: https://forums.rpgmakerweb.com/threads/maximum-call-stack-size-exceeded.154269/