[Solved] Preventing Common Event Call Overflow

Discussion in 'Learning Javascript' started by Nekohime1989, Feb 9, 2019.

Thread Status:
Not open for further replies.
  1. Nekohime1989

    Nekohime1989 'Monks Are Awesome' Veteran

    Messages:
    326
    Likes Received:
    133
    First Language:
    English
    Primarily Uses:
    RMMV
    Code:
    Game_Interpreter.prototype.checkOverflow = function() {
        if (this._depth >= 100) {
            throw new Error('Common event calls exceeded the limit');
        }
    };
    So this is how I have my function set up.
    Code:
    Game_Player.prototype.updateParams = function() {
        var index=null;
        var despairEnd=false;
        var insanityEnd=false;
        var hungerEnd=false;
        if ($gameUnit.deadMembers().length > 0) {
            $gameSwitches.setValue(Tamamo.Params.SoulSwitch, true);
        }
        HungerTimer+=1;
        if(HungerTimer===3600){
            HungerTimer=0;
        }
        for (var i = 0; i < 4; i++) {
            actor = $gameParty.actors[i].actorId;
            //hungertimer
            if(HungerTimer===0){
                $gameParty.actors[i].gainMp(-1);
                var shorthand =index+Tamamo.Params.HungerVariable;
                if($gameParty.actors[i].mp===0){
                    $gameVariables.setValue($gameVariables.value(shorthand)+1);
                    $gameParty.actors[i].gainMp($gameParty.actors[i].mmp);
                }
            }
            //dead ends
            //despair
            if($gameVariables.value(index+Tamamo.Params.DespairVariable)===1000) {
                despairEnd=true;
            }
            //insanity
            else if($gameVariables.value(index+Tamamo.Params.InsanityVariable)===1000) {
                insanityEnd=true;
            }
            //hunger
            else if($gameVariables.value(index+Tamamo.Params.HungerVariable)===4) {
                hungerEnd=true;
            }
        }
        if (despairEnd) $gameSwitches.setValue(Tamamo.Params.DespairSwitch, true);
        if (insanityEnd) $gameSwitches.setValue(Tamamo.Params.InsanitySwitch, true);
        if (hungerEnd) $gameSwitches.setValue(Tamamo.Params.HungerSwitch, true);
    }
    This function is called every frame and manages permadeath conditions for characters. However the common events are all Called with switches. four total.
    Basically I want to prevent any of these four common events from being called until one finishes. Do to the per frame basis. They would wind up stacking. And exceed the 100 limit. 60 frames = 1 second. So give it 4 seconds. And boom it explodes if enough of the conditions are met each frame that it runs. The function is called in Game_Player.update() btw.

    Basically they have a limit of one. leaving space for the other common events the game might need.

    How can I do this?

    edit: updated the code with the correct way of doing it.
     
    Last edited: Feb 12, 2019
    #1
  2. Kes

    Kes Global Moderators Global Mod

    Messages:
    20,593
    Likes Received:
    10,511
    First Language:
    English
    Primarily Uses:
    RMVXA

    This thread is being closed, due to being solved. If for some reason you would like this thread re-opened, please report this post and leave a message why. Thank you.

     
    #2
Thread Status:
Not open for further replies.

Share This Page