Added script, now another script is crashing the game...

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

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

    Nekohime1989 Cat Princess Veteran

    Messages:
    283
    Likes Received:
    102
    First Language:
    English
    Primarily Uses:
    RMMV
    Code:
    js/plugins/Olivia_AntiPlayerStress.js:331 TypeError: Cannot read property 'initialize' of undefined
        at Game_Player.initialize (js/plugins/TAMAMO_ActorManager.js:85)
        at new Game_Player (rpg_objects.js:7396)
        at Function.DataManager.createGameObjects (rpg_managers.js:213)
        at Function.DataManager.setupNewGame (rpg_managers.js:217)
        at Function.DataManager.setupNewGame (js/plugins/OrangeOverlay.js:223)
        at Scene_Boot.start (rpg_scenes.js:402)
        at Function.SceneManager.updateScene (rpg_managers.js:2019)
        at Function.SceneManager.updateMainNoFpsSynch (YEP_FpsSynchOption.js:210)
        at Function.SceneManager.updateMain (YEP_FpsSynchOption.js:203)
        at Function.SceneManager.update (rpg_managers.js:1907)
    I have no idea what is going on anymore. I added a custom new script I wrote. And all of sudden crash at launch, :(
    Here is the script I added.

    Code:
    //=============================================================================
    // Studio Tamamo - Actor Manager
    // Tamamo_ActorManager.js
    //=============================================================================
    
    var Imported = Imported || {};
    Imported.ActorManager = true;
    
    var Tamamo = Tamamo || {};
    Tamamo.ActorManager = Tamamo.ActorManager || {};
    
    //=============================================================================
     /*:
     * @plugindesc v1.0 Manages the actors' despair and insanity.
     * @author Palpaleos
     *
     * @param Soul Switch
     * @desc This switch will trigger the common event. It should be unique.
     * @default 1
     *
     * @param ---Despair---
     * @default
     *
     * @param Despair Variable
     * @desc A set of variables that represent this value.
     * @default 1
     *
     * @param Despair Switch
     * @desc This switch will trigger the common event. It should be unique.
     * @default 1
     *
     * @param ---Insanity---
     * @default
     *
     * @param Insanity Variable
     * @desc A set of variables that represent this value.
     * @default 5
     *
     * @param Insanity Switch
     * @desc This switch will trigger the common event. It should be unique.
     * @default 1
     *
     * @param ---Mood---
     * @default
     *
     * @param Mood Variable
     * @desc A set of variables that represent this value.
     * @default 9
     *
     *
     * @param ---Hunger---
     * @default
     *
     * @param Hunger Variable
     * @desc A set of variables that represent this value.
     * @default 13
     *
     * @param Hunger Switch
     * @desc This switch will trigger the common event. It should be unique.
     * @default 1
     */
    //=============================================================================
    
    //=============================================================================
    // Parameters
    //=============================================================================
    Tamamo.Parameters = PluginManager.parameters('Tamamo_ActorManager');
    Tamamo.Param = {};
    
    Tamamo.Param.SoulSwitch = Number(Tamamo.Parameters['Soul Switch'] || 2);
    Tamamo.Param.DespairVariable = Number(Tamamo.Parameters['Despair Variable'] || 1);
    Tamamo.Param.DespairSwitch = Number(Tamamo.Parameters['Despair Switch'] || 3);
    Tamamo.Param.InsanityVariable = Number(Tamamo.Parameters['Insanity Variable'] || 5);
    Tamamo.Param.InsanitySwitch = Number(Tamamo.Parameters['Insanity Switch'] || 4);
    Tamamo.Param.MoodVariable = Number(Tamamo.Parameters['Mood Variable'] || 9);
    Tamamo.Param.HungerVariable = Number(Tamamo.Parameters['Hunger Variable'] || 13);
    Tamamo.Param.HungerSwitch = Number(Tamamo.Parameters['Hunger Switch'] || 5);
    var HungerTimer=0;
    
    //=============================================================================
    // Game_Player
    //=============================================================================
    Tamamo.ActorManager.Game_Player_initialize = Game_Player.prototype.initialize;
    Game_Player.prototype.initialize = function() {
        Tamamo.Game_Player.initialize.call(this);
    }
    
    Tamamo.ActorManager.Game_Player_update = Game_Player.prototype.update;
    Game_Player.prototype.update = function(sceneActive) {
        if(sceneActive && $gameSwitches.value(Tamamo.GameInit)) {
            this.updateParams();
        }
        Tamamo.ActorManager.Game_Player_update.call(this);
    };
    
    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++) {
            index = $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-1)===1000) {
                despairEnd=true;
            }
            //insanity
            else if($gameVariables.value(index+Tamamo.Params.InsanityVariable-1)===1000) {
                insanityEnd=true;
            }
            //hunger
            else if($gameVariables.value(index+Tamamo.Params.HungerVariable-1)===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);
    }
    
    //=============================================================================
    // Game_Interpreter
    //=============================================================================
    Tamamo.ActorManager.Game_Interpreter_pluginCommand = Game_Interpreter.prototype.pluginCommand
    Game_Interpreter.prototype.pluginCommand = function(command, args) {
        Tamamo.ActorManager.Game_Interpreter_pluginCommand.call(this);
        if(commmand === 'setMood')
        {
            var index = $gameParty.actors[args[0]].actorId;
            var feelinfine = true;
            var mood;
            if(index+Tamamo.Params.DespairVariable-1 >=500) mood = 6;
            else if(index+Tamamo.Params.InsanityVariable-1 >=500) mood = 7;
            else {
                mood=args[0]
            }
            $gameVariables.setValue(Tamamo.Params.MoodVariable,mood);
        }
        if(commmand === 'fillHunger')
        {
            $gameActors.actor(args[0]).gainMp($gameActors.actor(args[0]).mmp);
            var index = $gameParty.actors[args[0]].actorId;
            var shorthand = index+Tamamo.Params.InsanityVariable-1;
            if($gameVariables.value(shorthand) > 0) {
                $gameVariables.setValue(shorthand,$gameVariables.value(shorthand)-1);
            }
        }
    };
    Did I make a mistake?
     
    #1
  2. Shaz

    Shaz Veteran Veteran

    Messages:
    37,307
    Likes Received:
    11,121
    Location:
    Australia
    First Language:
    English
    Primarily Uses:
    RMMV
    I don't see any reason why you would need to alias Game_Player.initialize - you've done nothing but call the original method. Unless you plan to add something else later.

    In fact, you've called it the wrong thing, and I think this is why it's crashing.

    Code:
    Tamamo.Game_Player.initialize.call(this);
    There is no such thing as Tamamo.Game_Player. You called it
    Tamamo.ActorManager.Game_Player_initialize
    so that's what should be in your call:

    Code:
    Tamamo.ActorManager.Game_Player_initialize.call(this);
     
    #2
    caethyril likes this.
  3. Kes

    Kes Global Moderators Global Mod

    Messages:
    20,358
    Likes Received:
    10,404
    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.

     
    #3
    GrayCrow likes this.
Thread Status:
Not open for further replies.

Share This Page