Cannot read property apply of undefined

● ARCHIVED · READ-ONLY
Started by jmike 6 posts View original ↗
  1. upload_2017-7-9_23-17-18.png

    Just when I thought I was getting the hang of plugin writing. Here's the offending section. I've googled and the usual culprits seem to be typos or wrong names. But I keep looking at my code and there doesn't seem to be a typo. Help?

    Code:
    Spoiler
    Code:
    function Scene_Adventure() {
            this.initialize.apply(this, arguments);
        };
    
        Scene_Adventure.prototype = Object.create(Scene_MenuBase.prototype);
        Scene_Adventure.prototype.constructor = Scene_Adventure;
    
        Scene_Adventure.prototype.initialize = function() {
            Scene_MenuBase.prototype.initialize.call(this);
        };
    
        Scene_Adventure.prototype.create = function() {
            Scene_MenuBase.prototype.create.call(this);
            
            this.createTitleWindow();
            this.createStoryWindow();
            this.createChoiceWindow();
            
            this.createSaveButton();
    
        };
    
        Scene_Adventure.prototype.start = function(){
            Scene_MenuBase.prototype.start.call(this);
        };
        
        Scene_Adventure.prototype.createTitleWindow = function() {
            this._TitleWindow = new Window_Title();
            this.addWindow(this._TitleWindow);
        };
        
        Scene_Adventure.prototype.createStoryWindow = function() {
            this._StoryWindow = new Window_Story();
            this.addWindow(this._StoryWindow);
        };
    
        Scene_Adventure.prototype.createChoiceWindow = function() {
            this._ChoiceWindow = new Window_ChoiceList();
            this.addWindow(this._ChoiceWindow);
            
            //Window_ChoiceList.start();
        };
        
        Scene_Adventure.prototype.createSaveButton = function() {
            this._SaveButton = new Window_SaveButton();
            this.addWindow(this._SaveButton);
        };
  2. Cannot read property of NULL or undefined may be a typo, but that typo is never the direct cause.

    of NULL or of undefined means that the engine tried to access an object that does not exist.

    That might be because you mistyped the object in a declaration, but often it means that you messed up the timing and tried to access the object before it was declared. For example some objects are only created when the option "newgame" is used on the titlescreen, if a function is called before that in a plugin it gets the same error if it tried to access those objects.
  3. xxxxx.initialize is a method (function?)
    means, it is an instruction.

    xxxxx.initialize.apply is ordering "apply" to the already ordered order of "initialize".
    you don't instruct instructions to do stuff, you instruct objects to do stuff.
  4. I actually just copied the structure of a previous plugin that I wrote (which works). So I don't know what's wrong with this one. It's a simple scene and window plugin. Would a solution be to declare the scene before it is push-ed into SceneManager? If so, how do I do that?
  5. gstv87 said:
    xxxxx.initialize is a method (function?)
    means, it is an instruction.

    xxxxx.initialize.apply is ordering "apply" to the already ordered order of "initialize".
    you don't instruct instructions to do stuff, you instruct objects to do stuff.

    I don't really know, I just went through tutorials by SRDude and Soul and that's how they wrote their scenes and windows. In fact I wrote this for another plugin of mine (which works) and there's no problem with the xxxxx.initialize.apply bit
    Code:
    function Scene_ShipGoods() {
            this.initialize.apply(this, arguments);
        }
    
        Scene_ShipGoods.prototype = Object.create(Scene_MenuBase.prototype);
        Scene_ShipGoods.prototype.constructor = Scene_ShipGoods;
    
        Scene_ShipGoods.prototype.initialize = function() {
            Scene_MenuBase.prototype.initialize.call(this);
        };
    
        Scene_ShipGoods.prototype.create = function() {
            Scene_MenuBase.prototype.create.call(this);
    
            this.createShipTitle();
            this.createShipCategory();
            this.createGoldWindow();
    
        };

    EDIT: Apologies for double posting, I meant to reply to Andar before a new post showed up.
  6. Line 317 and line 207 seem to be problems from the stack trace error. You should track your issue starting from line 317 and 207

    The '_msgWindow' in the class is null. Meaning you may have set it to null at some point or it wasn't created properly.

    The Scene is undefined on line 317, meaning that the class Scene_Adventure is undefined. Apply is used to pass arguments to a function.

    It would be helpful to see the file and look at what's up near those problem areas.