RMMZ How do I get my code called by game flow OR Maximum Call Stack Size in empty plugins

myenemy

Veteran
Veteran
Joined
Jan 17, 2014
Messages
67
Reaction score
30
First Language
Spanish
Primarily Uses
RMMV
I begun to make a lot of plugin scripts, but I've noticed many of them are incompatible together, getting "Maximum Call Stack Size" error.
I usually overwrite the default function like this:
Code:
var _savetheoriginalFUNCTION = FUNCTION; //Assume the function I call is named "FUNCTION", and it has no params

FUNCTION = function()
{
    //do whatever I want before it does the normal work
    _savetheoriginalFUNCTION.call(this);
    //do whatever I want after it does the normal work
};
The thing is, after doing this twice in different plugins, even if I name the vars _saveFUCTION1 and _saveFUNCTION2 over the same original function, I get the error popping.

For example, I'm currently working on a time/date system for ingame, and I need to save it into the savefile.
In order to do this, I worked on a mid-plugin as a core to enable a simpler management of the savefile for the developer.

Save Plugin snippet:
Code:
var _saveTheOriginalCreateGameObjects = DataManager.createGameObjects;

DataManager.createGameObjects = function()
{
    _saveTheOriginalCreateGameObjects.call(this); //Throws the error
    //$me_CustomSave= new ME_CustomSave();
};
Clock Plugin snippet:
Code:
var _saveTheOriginalSetupNewGame = DataManager.setupNewGame;

DataManager.setupNewGame = function() {
    _saveTheOriginalSetupNewGame.call(this); //If you do this in two plugins, with the same or different variable names, Max Call Stack error.
};

Sometimes, it even happens with no other plugins involved:

Code:
var _saveTheOriginalSceneMenuCreate=Scene_Menu.prototype.create;
Scene_Menu.prototype.create = function() {
        _saveTheOriginalSceneMenuCreate.call(this);
        this.createCalendarWindow(); //Create a customized window for the default menu with sample values.
    };
What other ways can I get my code called by normal game flow?
 

estriole

Veteran
Veteran
Joined
Jun 27, 2012
Messages
1,316
Reaction score
537
First Language
indonesian
either by adding your plugin name as the variable prefix or use some wrapper.

variable with plugin name prefix example:
Code:
var myPluginName_SceneMenuCreate = Scene_Menu.prototype.create;
Scene_Menu.prototype.create = function() {
        myPluginName_SceneMenuCreate.call(this);
        this.createCalendarWindow(); //Create a customized window for the default menu with sample values.
    };
wrapper example
Code:
var myPluginName = myPluginName || {};
(function($){
$.SceneMenuCreate = Scene_Menu.prototype.create;
Scene_Menu.prototype.create = function(){
        $.SceneMenuCreate.call(this);
        this.createCalendarWindow(); //Create a customized window for the default menu with sample values.
    };

})(myPluginName);
sorry if the code a little mess... typing on phone :p.

hope this help

edit: wait... you said you already use diferent name with your alias... it should already do the trick then... how many times you alias the same function in your project to get the maximum stack?


usually it happen when you install the same plugin twice or different plugin have the same alias name.

or something called an infinite loop.
 
Last edited:

myenemy

Veteran
Veteran
Joined
Jan 17, 2014
Messages
67
Reaction score
30
First Language
Spanish
Primarily Uses
RMMV
I've seen a lot of it, but never tried the wrapper approach in my plugins, your example is quite explanatory.
As you noticed in your edit, I already try naming them different in each plugin. More often than not, at the second alias of the same function in different plugins, gives me the max call stack size error. Sometimes even at the first, and it usually goes all the way down to tell me the issue is in pixi.js rather than my own code.

For example, many of my plugins need to start specifically after "New Game", or "Load Game" are run. It happens quite a lot in aliasing new game related functions, in clean projects with 2 plugins which only alias the same function once. (Plugins that exactly have the first example with different names).

I did browse a lot in this forum about it, that's why I did try some of the stuff. I find it odd, it rarely happened to me on MV.
 
Last edited:

CaRa_CrAzY

Undefined Custom Title
Veteran
Joined
Jan 19, 2019
Messages
65
Reaction score
27
First Language
Portuguese
Primarily Uses
Other
Maybe you got into an infinite loop by yourself.
You should check if the functions you are calling inside the aliased functions do not call the aliased function themselves again.

A full script would be also helpful for a better analysis.
 

estriole

Veteran
Veteran
Joined
Jun 27, 2012
Messages
1,316
Reaction score
537
First Language
indonesian
I've seen a lot of it, but never tried the wrapper approach in my plugins, your example is quite explanatory.
As you noticed in your edit, I already try naming them different in each plugin. More often than not, at the second alias of the same function in different plugins, gives me the max call stack size error. Sometimes even at the first, and it usually goes all the way down to tell me the issue is in pixi.js rather than my own code.

For example, many of my plugins need to start specifically after "New Game", or "Load Game" are run. It happens quite a lot in aliasing new game related functions, in clean projects with 2 plugins which only alias the same function once. (Plugins that exactly have the first example with different names).

I did browse a lot in this forum about it, that's why I did try some of the stuff. I find it odd, it rarely happened to me on MV.
can you try in blank project... then add those two plugins BUT only with the aliased function ONLY (delete the other part of the plugin). does it still throw error? if yes then the culprit is indeed multiple aliased function.... but if it work then something in your 'other' code is looping infinitely and not the alias that causing it. hope this help.
 

myenemy

Veteran
Veteran
Joined
Jan 17, 2014
Messages
67
Reaction score
30
First Language
Spanish
Primarily Uses
RMMV
I tried that before starting the thread. I thought I had explained already, but I guess I'm no good at explaining when I'm too obfuscated on why something that used to work in MV I can't make it again on MZ...
For example, many of my plugins need to start specifically after "New Game", or "Load Game" are run. It happens quite a lot in aliasing new game related functions, in clean projects with 2 plugins which only alias the same function once. (Plugins that exactly have the first example with different names).
I tried to explain I already tried that. I was most likely too ambiguous.

Maybe you got into an infinite loop by yourself.
You should check if the functions you are calling inside the aliased functions do not call the aliased function themselves again.

A full script would be also helpful for a better analysis.
Code:
var _saveTheOriginalSetupNewGame = DataManager.setupNewGame;

DataManager.setupNewGame = function() {
    _saveTheOriginalSetupNewGame.call(this); //If you do this in two plugins, with the same or different variable names, Max Call Stack error.
};
A full reading would help too. Although it's my fault for being so confused and not explaining properly...

Somehow forum did not save my edit.

I'm sorry I can't explain the issue more clearly, I'm too confused about things that used to go well for me on MV don't always work just so fine on MZ for no apparent reason, and my mind is really blocked. I can't even format the main post so it's easier to understand. I thank you both a lot for trying to understand my mess and help me.
 
Last edited:

estriole

Veteran
Veteran
Joined
Jun 27, 2012
Messages
1,316
Reaction score
537
First Language
indonesian
I tried that before starting the thread. I thought I had explained already, but I guess I'm no good at explaining when I'm too obfuscated on why something that used to work in MV I can't make it again on MZ...

I tried to explain I already tried that. I was most likely too ambiguous.



A full reading would help too. Although it's my fault for being so confused and not explaining properly...

Somehow forum did not save my edit.

I'm sorry I can't explain the issue more clearly, I'm too confused about things that used to go well for me on MV don't always work just so fine on MZ for no apparent reason, and my mind is really blocked. I can't even format the main post so it's easier to understand. I thank you both a lot for trying to understand my mess and help me.
how about:
1. create blank project
2. add only 2 plugins conflicting
(only with the function aliased inside. delete the rest of the code and only leave the aliased function).
3. playtest to see if error happen
4. if the error replicated 100% all the time... upload the project in google drive or something
5. share the link so we can check it.

hope this help
 

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

Latest Threads

Latest Posts

Latest Profile Posts

Our latest feature is an interview with... me?!

People4_2 (Capelet off and on) added!

Just beat the last of us 2 last night and starting jedi: fallen order right now, both use unreal engine & when I say i knew 80% of jedi's buttons right away because they were the same buttons as TLOU2 its ridiculous, even the same narrow hallway crawl and barely-made-it jump they do. Unreal Engine is just big budget RPG Maker the way they make games nearly identical at its core lol.
Can someone recommend some fun story-heavy RPGs to me? Coming up with good gameplay is a nightmare! I was thinking of making some gameplay platforming-based, but that doesn't work well in RPG form*. I also was thinking of removing battles, but that would be too much like OneShot. I don't even know how to make good puzzles!
one bad plugin combo later and one of my followers is moonwalking off the screen on his own... I didn't even more yet on the new map lol.

Forum statistics

Threads
106,035
Messages
1,018,455
Members
137,821
Latest member
Capterson
Top