Max call stack exceeded with Victor's Passive States

Discussion in 'Javascript/Plugin Support' started by Omega Weapon, Aug 2, 2019.

Thread Status:
Not open for further replies.
  1. Omega Weapon

    Omega Weapon AKA Laura Veteran

    Messages:
    829
    Likes Received:
    257
    Location:
    Netherlands
    First Language:
    Dutch
    Primarily Uses:
    RMMV
    So I ran into this error.

    I'm using Victor's Passive States, Galv's Magic Shards and my own custom plugin for handling a few variables.

    However, I get a "Max call stack exceeded" error with Victor's plugin.

    upload_2019-8-1_21-30-13.png
    error and stack trace. (the syntax errors are all fixed now)

    And this is the notetag of one of my actors:
    Code:
    <custom passive state: 27>
    result = $gameParty.social > 7;
    </custom passive state>
    <custom passive state: 26>
    result = ($gameParty.social > 5 && $gameParty.social < 8);
    </custom passive state>
    <custom passive state: 25>
    result = ($gameParty.social > 3 && $gameParty.social < 6);
    </custom passive state>
    <custom passive state: 24>
    result = $gameParty.stem > 7;
    </custom passive state>
    <custom passive state: 23>
    result = ($gameParty.stem > 5 && $gameParty.stem < 8);
    </custom passive state>
    <custom passive state: 22>
    result = ($gameParty.stem > 3 && $gameParty.stem < 6);
    </custom passive state>
    <custom passive state: 21>
    result = $gameParty.languages > 7;
    </custom passive state>
    <custom passive state: 20>
    result = ($gameParty.languages > 5 && $gameParty.languages < 8);
    </custom passive state>
    <custom passive state: 19>
    result = ($gameParty.languages > 3 && $gameParty.languages < 6);
    </custom passive state>
    <custom passive state: 18>
    result = $gameParty.physical > 7;
    </custom passive state>
    <custom passive state: 17>
    result = ($gameParty.physical > 5 && $gameParty.physical  < 8);
    </custom passive state>
    <custom passive state: 16>
    result = ($gameParty.physical  > 3 && $gameParty.physical  < 6);
    </custom passive state>
    
    <custom passive state: 11>
    result = $gameActors.actor(1).science > 3;
    </custom passive state>
    <custom passive state: 12>
    result =  $gameActors.actor(1).floaty > 3;
    </custom passive state>
    <custom passive state: 13>
    result =  $gameActors.actor(1).dangerous > 3;
    </custom passive state>
    <custom passive state: 14>
    result =  $gameActors.actor(1).boring > 3;
    </custom passive state>
    <custom passive state: 15>
    result =  $gameActors.actor(1).practical > 3;
    </custom passive state>
    (the social, physical, stem, languages, and science, floaty, dangerous, practical are my custom fields I added to the party and actors, and are used to manage an auto-chess like buff system)

    Am I simply using too many custom conditions?




    Before anyone says "get Yanfly's", I'm using Victor's CTB, and I don't know if Yanfly's is compatible with that. I go for no.
     
    #1
  2. Restart

    Restart Veteran Veteran

    Messages:
    201
    Likes Received:
    130
    First Language:
    English
    Primarily Uses:
    RMMV
    The first thing you should check is to see if there's an infinite loop, where states keep triggering each other.

    Can you tell it to console.log the name of a new state whenever it's applied, and see what happens there?
     
    #2
  3. Omega Weapon

    Omega Weapon AKA Laura Veteran

    Messages:
    829
    Likes Received:
    257
    Location:
    Netherlands
    First Language:
    Dutch
    Primarily Uses:
    RMMV
    This happens before I even get to the title screen
     
    #3
  4. Hudell

    Hudell Dog Lord Veteran

    Messages:
    3,316
    Likes Received:
    2,931
    Location:
    Brazil
    First Language:
    Portuguese
    Primarily Uses:
    RMMV
    1. The ShardChecker plugin is not being loaded due to invalid syntax.
    2. The infinite loop seems to be triggered by galv's script on the Game_Actor.setup method. Can you share the code of that method?
     
    #4
  5. Omega Weapon

    Omega Weapon AKA Laura Veteran

    Messages:
    829
    Likes Received:
    257
    Location:
    Netherlands
    First Language:
    Dutch
    Primarily Uses:
    RMMV
    In the mean time, I got all of the syntax errors out of ShardChecker. Still a bit new to JavaScript.

    Here you go, Hudell.
    Code:
    Galv.MS.Game_Actor_setup = Game_Actor.prototype.setup;
    Game_Actor.prototype.setup = function(actorId) {
        Galv.MS.Game_Actor_setup.call(this,actorId);
        this.initShards();
    };
    
    Game_Actor.prototype.initShards = function() {
        this._shardSlots = 0;    // Current shard slots actor has unlocked
        this._shards = {};       // Crate equipped shard object
        this._shardLocks = [];    // array of shard slot ID's (1 being first, 2 being second etc)
        var img = $dataActors[this._actorId].note.toLowerCase().match(/<shardimg:(.*)>/i)  // Shard Image ID
        this._shardImg = img ? Number(img[1]) : 0;
    };
     
    #5
  6. Hudell

    Hudell Dog Lord Veteran

    Messages:
    3,316
    Likes Received:
    2,931
    Location:
    Brazil
    First Language:
    Portuguese
    Primarily Uses:
    RMMV
    Try opening the debugger and placing a breakpoint there, then follow the code line by line to find out where the loop is.
     
    #6
  7. Omega Weapon

    Omega Weapon AKA Laura Veteran

    Messages:
    829
    Likes Received:
    257
    Location:
    Netherlands
    First Language:
    Dutch
    Primarily Uses:
    RMMV
    How do you do that when the error happens before you even get to a title sceen?

    And my current IDE isnt set up for MV debugging... (I use Unity mainly, with Visual Studio 2017)
     
    #7
  8. Hudell

    Hudell Dog Lord Veteran

    Messages:
    3,316
    Likes Received:
    2,931
    Location:
    Brazil
    First Language:
    Portuguese
    Primarily Uses:
    RMMV
    You can debug from MV's console, no need for the IDE.
    If it doesn't open the console by pressing F8 after the error, you can change the package.json file to toggle on the toolbar, it'll let you open it anytime.
    Then you can place the breakpoint and hit Ctrl+R (on the debugger) to reload the game.
     
    #8
  9. Omega Weapon

    Omega Weapon AKA Laura Veteran

    Messages:
    829
    Likes Received:
    257
    Location:
    Netherlands
    First Language:
    Dutch
    Primarily Uses:
    RMMV
    So I've ran through the debugger.... which took ages. The problem still looks to me like it's with Victor's. And it looked like my notetags weren't processed properly
     
    #9
  10. Hudell

    Hudell Dog Lord Veteran

    Messages:
    3,316
    Likes Received:
    2,931
    Location:
    Brazil
    First Language:
    Portuguese
    Primarily Uses:
    RMMV
    Did you notice which methods it ran through multiple times for the same actor?
     
    #10
  11. Omega Weapon

    Omega Weapon AKA Laura Veteran

    Messages:
    829
    Likes Received:
    257
    Location:
    Netherlands
    First Language:
    Dutch
    Primarily Uses:
    RMMV
    Not exactly. It looked like gibberish.

    But I also tested something else. The error only appears when Victor's is active. (Along with his core script). Even if Galv's and mine are OFF.

    But I'll continue the search for the error tomorrow. It's past 11.30 pm here
     
    #11
  12. Omega Weapon

    Omega Weapon AKA Laura Veteran

    Messages:
    829
    Likes Received:
    257
    Location:
    Netherlands
    First Language:
    Dutch
    Primarily Uses:
    RMMV
    I have found something:
    upload_2019-8-5_16-15-21.png
    It took me a while to find, but I've found that this part will keep looping the initialization of the party members. Literally seeing an entire iteration appear in the stack, from Game_Actor.initialize
    upload_2019-8-5_16-19-27.png
    This is no good. And there are more than four iterations of this.

    Galv's has nothing to do with this.



    EDIT: I have found in a clean project that the error starts to appear after I add my notetag to my Actor.
    So it might be my first theory after all: too many custom checks.
     
    Last edited: Aug 7, 2019
    #12
  13. Omega Weapon

    Omega Weapon AKA Laura Veteran

    Messages:
    829
    Likes Received:
    257
    Location:
    Netherlands
    First Language:
    Dutch
    Primarily Uses:
    RMMV
    Okay. First of all, sorry for doubleposting, but I have found something significant.
    It seems the problem is with my own plugin, and the notetags that refer to them.

    The fields/parameters/properties I added through it are not working with the notetags.
    At least, I found out after I split my notetags up and divided them over actors and classes.

    I still don't fully understand what is happening. The loops start with Victor's plugin.
    I have run the plugin through it, and I don't know what the metadata is supposed to look like, but it's like this:
    upload_2019-8-7_23-55-17.png
    This hasn't changed since the start of this thread.
    upload_2019-8-7_23-56-24.png
    class data for reference
    And if I call one of the fields through the console, this happens:
    upload_2019-8-7_23-57-48.png

    stack trace for the main error:
    upload_2019-8-7_23-59-35.png

    So it's a compatibilty issue after all.
    Now, I don't know Victor's scripts, and I rather not mess with his code.
    But I feel like I made a mistake in my plugin.

    And here is my full plugin:
    Code:
    var Imported = Imported || {};
    Imported.OmegaWeapon_ShardChecker = true;
    
    var OmegaWeapon = OmegaWeapon || {};
    OmegaWeapon.SC = OmegaWeapon.SC || {};
    
    //-----------------------------------------------------------------------------
    /*:
     * @plugindesc An addon for Galv's Magic Shards to update values passively
     *
     * @author OmegaWeapon
     * @help
     *    This plugin adds some variables to actors so it can check whether certain states should be active or not
     *  depending on which shards they have equipped
     *     Might be changed to a generic thing for auto-chess like party buffs
     */
     
    // Adding parameters to Game_Actor
    var Game_Actor_initMembers = Game_Actor.prototype.initMembers;
    Game_Actor.prototype.initMembers = function()
     {
        Game_Actor_initMembers.call(this);
        this._Science = 0;
        this._Floaty = 0;
        this._Dangerous = 0;
        this._Boring = 0;
        this._Practical = 0;
     };
     
     
    var Game_Actor_setup = Game_Actor.prototype.setup;
    Game_Actor.prototype.setup = function (actorId) {
       Game_Actor_setup.call(this, actorId);
       var actor = $dataActors[actorId];
       this._Science = actor.science;
       this._Floaty = actor.floaty;
       this._Dangerous = actor.dangerous;
       this._Boring = actor.boring;
       this._Practical = actor.practical;
    };
    
    Game_Actor.prototype.science = function() {
        return this._Science;
    };
    Game_Actor.prototype.floaty = function() {
        return this._Floaty;
    };
    Game_Actor.prototype.dangerous = function() {
        return this._Dangerous;
    };
    Game_Actor.prototype.boring = function() {
        return this._Boring;
    };
    Game_Actor.prototype.practical = function() {
        return this._Practical;
    };
    
    // Adding party wide parameters to Game_Party
    var Game_Party_Initialize = Game_Party.prototype.initialize;
    Game_Party.prototype.initialize = function()
    {
        Game_Party_Initialize.call(this);
        this._Physical = 0;
        this._Languages = 0;
        this._STEM = 0;
        this._Social = 0;
    };
    
    Game_Party.prototype.physical =  function()
    {
        return this._Physical;
    };
    Game_Party.prototype.languages =  function()
    {
        return this._Languages;
    };
    Game_Party.prototype.stem =  function()
    {
        return this._STEM;
    };
    Game_Party.prototype.social =  function()
    {
        return this._Social;
    };
    
    //And now we're going to do the fun stuff
    function CheckParty()
    {
        $gameParty.physical = 0;
        $gameParty.stem = 0;
        $gameParty.languages = 0;
        $gameParty.social = 0;
        if($gameParty.hasShard(1))
        {
            $gameParty.physical += 1;
            $gameParty.languages += 1;
        };
        if($gameParty.hasShard(2))
        {
            $gameParty.stem += 1;
            $gameParty.social += 1;
        };
        if($gameParty.hasShard(3))
        {
            $gameParty.physical += 1;
            $gameParty.languages += 1;
        };
        if($gameParty.hasShard(4))
        {
            $gameParty.stem += 1;
            $gameParty.social += 1;
        };
        if($gameParty.hasShard(5))
        {
            $gameParty.physical += 1;
            $gameParty.social += 1;
        };
        if($gameParty.hasShard(6))
        {
            $gameParty.stem += 1;
            $gameParty.languages += 1;
        };
        if($gameParty.hasShard(7))
        {
            $gameParty.physical += 1;
            $gameParty.stem += 1;
        };
        if($gameParty.hasShard(8))
        {
            $gameParty.stem += 1;
            $gameParty.languages += 1;
        };   
        if($gameParty.hasShard(9))
        {
            $gameParty.social += 1;
            $gameParty.languages += 1;
        };
        if($gameParty.hasShard(10))
        {
            $gameParty.physical += 1;
            $gameParty.social += 1;
        };
        if($gameParty.hasShard(11))
        {
            $gameParty.physical += 1;
            $gameParty.stem += 1;
        };
        if($gameParty.hasShard(12))
        {
            $gameParty.social += 1;
            $gameParty.languages += 1;
        };
        if($gameParty.hasShard(13))
        {
            $gameParty.physical += 1;
            $gameParty.stem += 1;
        };
        if($gameParty.hasShard(14))
        {
            $gameParty.social += 1;
            $gameParty.languages += 1;
        };
        if($gameParty.hasShard(15))
        {
            $gameParty.stem += 1;
            $gameParty.social += 1;
        };
        if($gameParty.hasShard(16))
        {
            $gameParty.physical += 1;
            $gameParty.languages += 1;
        };
        if($gameParty.hasShard(17))
        {
            $gameParty.physical += 1;
            $gameParty.languages += 1;
        };
        if($gameParty.hasShard(18))
        {
            $gameParty.social += 1;
            $gameParty.stem += 1;
        };
        if($gameParty.hasShard(19))
        {
            $gameParty.physical += 1;
            $gameParty.stem += 1;
        };
        if($gameParty.hasShard(20))
        {
            $gameParty.social += 1;
            $gameParty.languages += 1;
        };
        
        CheckActor(1);
        CheckActor(2);
        CheckActor(3);
        CheckActor(4);
    };
    
    function CheckActor(actorId){
        
        $gameActors.actor(actorId).science = 0;
        $gameActors.actor(actorId).floaty = 0;
        $gameActors.actor(actorId).dangerous = 0;
        $gameActors.actor(actorId).boring = 0;
        $gameActors.actor(actorId).practical = 0;
        
        if($gameActors.actor(actorId).hasShard(1)){
            $gameActors.actor(actorId).science += 1;
            $gameActors.actor(actorId).floaty += 1;
        };
        if($gameActors.actor(actorId).hasShard(2)){
            $gameActors.actor(actorId).science += 1;
            $gameActors.actor(actorId).dangerous += 1;
        };
        if($gameActors.actor(actorId).hasShard(3)){
            $gameActors.actor(actorId).dangerous += 1;
            $gameActors.actor(actorId).boring += 1;
        };
        if($gameActors.actor(actorId).hasShard(4)){
            $gameActors.actor(actorId).science += 1;
            $gameActors.actor(actorId).practical += 1;
        };
        if($gameActors.actor(actorId).hasShard(5)){
            $gameActors.actor(actorId).floaty += 1;
            $gameActors.actor(actorId).dangerous += 1;
        };
        if($gameActors.actor(actorId).hasShard(6)){
            $gameActors.actor(actorId).floaty += 1;
            $gameActors.actor(actorId).practical += 1;
        };
        if($gameActors.actor(actorId).hasShard(7)){
            $gameActors.actor(actorId).science += 1;
            $gameActors.actor(actorId).boring += 1;
        };
        if($gameActors.actor(actorId).hasShard(8)){
            $gameActors.actor(actorId).floaty += 1;
            $gameActors.actor(actorId).boring += 1;
        };
        if($gameActors.actor(actorId).hasShard(9)){
            $gameActors.actor(actorId).dangerous += 1;
            $gameActors.actor(actorId).practical += 1;
        };
        if($gameActors.actor(actorId).hasShard(10)){
            $gameActors.actor(actorId).boring += 1;
            $gameActors.actor(actorId).practical += 1;
        };
        if($gameActors.actor(actorId).hasShard(11)){
            $gameActors.actor(actorId).floaty += 2;
        };
        if($gameActors.actor(actorId).hasShard(12)){
            $gameActors.actor(actorId).floaty += 2;
        };
        if($gameActors.actor(actorId).hasShard(13)){
            $gameActors.actor(actorId).science += 2;
        };
        if($gameActors.actor(actorId).hasShard(14)){
            $gameActors.actor(actorId).science += 2;
        };
        if($gameActors.actor(actorId).hasShard(15)){
            $gameActors.actor(actorId).dangerous += 2;
        };
        if($gameActors.actor(actorId).hasShard(16)){
            $gameActors.actor(actorId).dangerous += 2;
        };
        if($gameActors.actor(actorId).hasShard(17)){
            $gameActors.actor(actorId).boring += 2;
        };
        if($gameActors.actor(actorId).hasShard(18)){
            $gameActors.actor(actorId).boring += 2;
        };
        if($gameActors.actor(actorId).hasShard(19)){
            $gameActors.actor(actorId).practical += 2;
        };
        if($gameActors.actor(actorId).hasShard(20)){
            $gameActors.actor(actorId).practical += 2;
        };
    }
    
    //Add a call into the pop method of scenes
    var Scene_Menu_Pop = Scene_Menu.prototype.popScene;
    Scene_Menu.prototype.popScene = function(){
        Scene_Menu_Pop.call(this);
        CheckParty();
    };
    var Scene_Equip_Pop = Scene_Equip.prototype.popScene;
    Scene_Equip.prototype.popScene = function(){
        Scene_Equip_Pop.call(this);
        CheckParty();
    };
    var Scene_Status_Pop = Scene_Status.prototype.popScene;
    Scene_Status.prototype.popScene = function(){
        Scene_Status_Pop.call(this);
        CheckParty();
    };
    var Scene_Item_Pop = Scene_Item.prototype.popScene;
    Scene_Item.prototype.popScene = function(){
        Scene_Item_Pop.call(this);
        CheckParty();
    };
    var Scene_Skill_Pop = Scene_Skill.prototype.popScene;
    Scene_Skill.prototype.popScene = function(){
        Scene_Skill_Pop.call(this);
        CheckParty();
    };
    var Scene_MenuBase_Pop = Scene_MenuBase.prototype.popScene;
    Scene_MenuBase.prototype.popScene = function(){
        Scene_MenuBase_Pop.call(this);
        CheckParty();
    };
    Do I need to change stuff to access my parameters/fields/properties/you name it?

    Again, sorry for doubleposting, but I felt like this was too significant to end up in an Edit.
     
    #13
  14. Hudell

    Hudell Dog Lord Veteran

    Messages:
    3,316
    Likes Received:
    2,931
    Location:
    Brazil
    First Language:
    Portuguese
    Primarily Uses:
    RMMV
    You're accessing $gameActors.actor(1) in the first actor's note. If that note is parsed on initialization, then that is your error.

    Try replacing
    Code:
    $gameActors.actor(1).science
    
    for

    Code:
    ($dataActors[1].science || $gameActors.actor(1).science)
    
    
     
    #14
  15. Omega Weapon

    Omega Weapon AKA Laura Veteran

    Messages:
    829
    Likes Received:
    257
    Location:
    Netherlands
    First Language:
    Dutch
    Primarily Uses:
    RMMV
    So that not being called correctly caused the loop. okay.

    But I have a similar part on the notetags that checks on the Party, but that part doesn't cause errors. Which is why I thought it was something to do with my plugin.

    Edit: Uhh... nope. It still loops.
    upload_2019-8-8_15-44-36.png
    The passive states are now initialized somewhat correctly, I think.

    BUT! I don't see my fields on the actors, but they exist on the party. Uh, it seems that the way I made the fields doesn't work.
     
    Last edited: Aug 8, 2019
    #15
  16. Hudell

    Hudell Dog Lord Veteran

    Messages:
    3,316
    Likes Received:
    2,931
    Location:
    Brazil
    First Language:
    Portuguese
    Primarily Uses:
    RMMV
    Can you share the code of the script that reads those notes?
     
    #16
  17. Omega Weapon

    Omega Weapon AKA Laura Veteran

    Messages:
    829
    Likes Received:
    257
    Location:
    Netherlands
    First Language:
    Dutch
    Primarily Uses:
    RMMV
    #17
  18. Hudell

    Hudell Dog Lord Veteran

    Messages:
    3,316
    Likes Received:
    2,931
    Location:
    Brazil
    First Language:
    Portuguese
    Primarily Uses:
    RMMV
    The problem is that Victor's plugin is trying to parse the script you used on the notetags before the actors are instantiated, so using $gameActors.actor(1) there will always trigger this error.
     
    #18
  19. Omega Weapon

    Omega Weapon AKA Laura Veteran

    Messages:
    829
    Likes Received:
    257
    Location:
    Netherlands
    First Language:
    Dutch
    Primarily Uses:
    RMMV
    Hmm. I tried switching the plugins around, but that didn't help.

    Is there anything that can be done?
     
    #19
  20. Omega Weapon

    Omega Weapon AKA Laura Veteran

    Messages:
    829
    Likes Received:
    257
    Location:
    Netherlands
    First Language:
    Dutch
    Primarily Uses:
    RMMV
    I managed to solve the problem using the variables in the engine, and then editing them in the plugin.
    Victor's plugin doesn't get iffy with those.

    I learnt a lot from this adventure with JavaScript. Until next time!
    And definitely thanks to Aloe Guvner and Hudell for the help.
     
    #20
Thread Status:
Not open for further replies.

Share This Page