Undefined is not a function

● ARCHIVED · READ-ONLY
Started by VexGaming 10 posts View original ↗
  1. As you can see i'm trying to create a sample window and scene for an additional option in the menu but whenever i select the option it would just say that typeerror:undefined is not a function. I traced the problem and its because of this line: this._techniqueWindow = new Window_Equip_Technique(); however if i change the colored line with some of the window precreated like new Window_Options() it would work. i hope someone could enlighten me with this.

    edit: btw i also used main menu manager of yanfly

    Code:
    function Window_Equip_Technique() {
        this.initialize.apply(this, arguments);
    }
    
    Window_Equip_Technique.prototype = Object.create(Window_Base.prototype);
    Window_Equip_Technique.prototype.constructor = Window_Equip_Technique;
    
    Window_Equip_Technique.prototype.initialize = function() {
        var width = this.windowWidth();
        var height = this.windowHeight();
        var x = (Graphics.boxWidth - this.width) / 2;
        var y = (Graphics.boxHeight - this.height) / 2;
        Window_Base.prototype.initialize.call(this, x, y, width, height);
    };
    
    Window_Equip_Technique.prototype.windowWidth = function() {
        return 480;
    }
    
    Window_Equip_Technique.prototype.windoHeight = function() {
        return 240;
    }
    
    Window_Equip_Technique.prototype.refresh = function() {
        this.contents.clear();
        this.drawTextEx("OMG..", 0, 0);
    };
    
    Window_Equip_Technique.prototype.open = function() {
        this.refresh();
        Window_Base.prototype.open.call(this);
    };
    
    // Scene
    
    // var _Scene_Menu_createCommandWindow = Scene_Menu.prototype.create;
    // Scene_Menu.prototype.createCommandWindow = function() {
    //     _Scene_Menu_createCommandWindow.call(this);
    //     this._commandWindow.setHandler('technique',    this.commandTechnique.bind(this));
    // };
    
    Scene_Menu.prototype.commandTechnique = function() {
         SceneManager.push(Scene_Technique);
    };
    
    //Scene
    
    function Scene_Technique() {
        this.initialize.apply(this, arguments);
    }
    
    Scene_Technique.prototype = Object.create(Scene_MenuBase.prototype);
    Scene_Technique.prototype.constructor = Scene_Technique;
    
    Scene_Technique.prototype.initialize = function() {
        Scene_MenuBase.prototype.initialize.call(this);
    };
    
    Scene_Technique.prototype.create = function() {
        Scene_MenuBase.prototype.create.call(this);
        this._techniqueWindow = new Window_Equip_Technique();
        this._techniqueWindow.setHandler('cancel', this.popScene.bind(this));
        this.addWindow(this._techniqueWindow);
    };
    
    Scene_Technique.prototype.start = function() {
        Scene_MenuBase.prototype.start.call(this);
    };
    
    
    //Window
  2. It's a pity you didn't view the console by pressing f8. It can show you where the error is.
    Screenshot_511.png
    The very first line only says what kind of an error it is. In this case dadada is not defined, in your case undefined is not a function.
    Btw. undefined is not a function means you're trying to call a class method that is not defined.
    The second line shows where the error is located. In my case it's inside a function DataManager.makeSavefileInfo. Next to it there's a script name and the line where exactly this error is. I censored the name of the script, but then there's also 2094 - line where the mistake is located. The rest is irrelevant, it's just a stack of function calls that led to this mistake.
    You'd see this way that you have a typo in one of your functions, specifically in windoHeight. So you defined windoHeight, but are calling windowHeight.
  3. @Poryg is correct.
    The error you're experiencing is because windowHeight is undefined (you defined windoHeight instead).

    Just to be sure, I had a look at Window_Base (which Window_Equip_Technique inherits from), and windowHeight is not defined there (or in any of its ancestors) either.
  4. AH! SH*T ME. HAHAHAHA if i can just turn back time and not post this haha ok i forgot how to open console but thanks for helping me. my bad.

    edit: also are there some tutorials or manual about the basic functions?
  5. I don't know about any real tutorials. The best teacher is experience.
  6. true2 ok ok lastly i hope i don't sound demanding and idiotic i manage to create the window now the problem is giving it some handler so at this line: this._techniqueWindow.setHandler('cancel', this.popScene.bind(this)); It's giving the same typeerror. i wanted to make it so that whenever i enter technique command i can return to the menu by pressing cancel

    Spoiler
    Code:
    function Window_Equip_Technique() {
        this.initialize.apply(this, arguments);
    }
    
    Window_Equip_Technique.prototype = Object.create(Window_Base.prototype);
    Window_Equip_Technique.prototype.constructor = Window_Equip_Technique;
    
    Window_Equip_Technique.prototype.initialize = function() {
        var width = this.windowWidth();
        var height = this.windowHeight();
        var x = (Graphics.boxWidth - width) / 2;
        var y = (Graphics.boxHeight - height) / 2;
        Window_Base.prototype.initialize.call(this, x, y, width, height);
        this.refresh();
    };
    
    Window_Equip_Technique.prototype.windowWidth = function() {
        return 480;
    }
    
    Window_Equip_Technique.prototype.windowHeight = function() {
        return 240;
    }
    
    Window_Equip_Technique.prototype.refresh = function() {
        this.contents.clear();
        this.drawTextEx("OMG..", 0, 0);
    };
    
    Window_Equip_Technique.prototype.open = function() {
        this.refresh();
        Window_Base.prototype.open.call(this);
    };
    
    // Scene
    
    // var _Scene_Menu_createCommandWindow = Scene_Menu.prototype.create;
    // Scene_Menu.prototype.createCommandWindow = function() {
    //     _Scene_Menu_createCommandWindow.call(this);
    //     this._commandWindow.setHandler('technique',    this.commandTechnique.bind(this));
    // };
    
    Scene_Menu.prototype.commandTechnique = function() {
         SceneManager.push(Scene_Technique);
    };
    
    //Scene
    
    function Scene_Technique() {
        this.initialize.apply(this, arguments);
    }
    
    Scene_Technique.prototype = Object.create(Scene_MenuBase.prototype);
    Scene_Technique.prototype.constructor = Scene_Technique;
    
    Scene_Technique.prototype.initialize = function() {
        Scene_MenuBase.prototype.initialize.call(this);
    };
    
    Scene_Technique.prototype.create = function() {
        Scene_MenuBase.prototype.create.call(this);
        this._techniqueWindow = new Window_Equip_Technique();
        this._techniqueWindow.setHandler('cancel', this.popScene.bind(this));
        this.addWindow(this._techniqueWindow);
    };
    
    
    Scene_Technique.prototype.start = function() {
        Scene_MenuBase.prototype.start.call(this);
    };
    
    
    //Window

    iAENFU7.png
  7. In other to use handlers, the window needs to be prototype of Window_Command, not Window_Base.
  8. thank you now i understand.:kaojoy:
  9. Poryg said:
    In other to use handlers, the window needs to be prototype of Window_Command, not Window_Base.
    *technically, Window_Selectable not Window_Command :wink:
  10. A small mistake, sorry :D