SetHandler ERROR

ValiLey

Warper
Member
Joined
May 2, 2017
Messages
4
Reaction score
0
First Language
German
Primarily Uses
RMMV
Hi guys,

I'm new to Javaskript and I don't quite get the setHandler functions.
What I'm trying to do:
I created a new menu option called "worldtree".
It's supposed to open a window and display an image.
And when you press ESC you get back to the menu.

I used some tutorials to create the window and draw the image, BUT whenever I open the window, I'm stuck.
I can't get back to the menu.
If I got it right (?), I need a setHandler to do this. The thing is, everytime I add the setHandler to my code I get an ERROR (TypeError undefined is not a function).
So my question is, how do these setHandlers work and what do I have to do to close the window?

Thanks in Advance :)

Code:
//Scene

Scene_Menu.prototype.commandWorldtree = function() {
    SceneManager.push(Worldtree_Scene);
};

function Worldtree_Scene() {
    this.initialize.apply(this, arguments);
}

Worldtree_Scene.prototype = Object.create(Scene_MenuBase.prototype);
Worldtree_Scene.prototype.constructor = Worldtree_Scene;

Worldtree_Scene.prototype.initialize = function() {
   Scene_MenuBase.prototype.initialize.call(this);
};

Worldtree_Scene.prototype.stop = function() {
    Scene_MenuBase.prototype.stop.call(this);
};

Worldtree_Scene.prototype.terminate = function() {
    Scene_MenuBase.prototype.terminate.call(this);
};

Worldtree_Scene.prototype.start = function() {
    Scene_MenuBase.prototype.start.call(this);
};

Worldtree_Scene.prototype.create = function() {
    Scene_MenuBase.prototype.create.call(this);
    this._worldtreeWindow = new Window_Worldtree(0,0);
    this._worldtreeWindow.setHandler('cancel', this.popScene.bind(this));
    this._worldtreeWindow.activate();
    this.addWindow(this._worldtreeWindow);
};
 

Poryg

Dark Lord of the Castle of Javascreeps
Veteran
Joined
Mar 23, 2017
Messages
4,125
Reaction score
10,639
First Language
Czech
Primarily Uses
RMMV
And where do you have your Window_Worldtree defined?

It looks like this is at fault.

Code:
Worldtree_Scene.prototype.create = function() {
    Scene_MenuBase.prototype.create.call(this);
    this._worldtreeWindow = new Window_Worldtree(0,0);
    this._worldtreeWindow.setHandler('cancel', this.popScene.bind(this));
    this._worldtreeWindow.activate();
    this.addWindow(this._worldtreeWindow);
};
I don't see where you defined Window_Worldtree, if you even defined it.
 

ValiLey

Warper
Member
Joined
May 2, 2017
Messages
4
Reaction score
0
First Language
German
Primarily Uses
RMMV
Oh, it's here:
Code:
function Window_Worldtree() {
    this.initialize.apply(this, arguments);
}

Window_Worldtree.prototype = Object.create(Window_Base.prototype);
Window_Worldtree.prototype.constructor = Window_Worldtree;

Window_Worldtree.prototype.initialize = function(x, y) {
    var width = this.windowWidth();
    var height = this.windowHeight();
    Window_Base.prototype.initialize.call(this, x, y, width, height);
    this.refresh();
    
};

Window_Worldtree.prototype.windowWidth = function() {
    return Graphics.width;
};

Window_Worldtree.prototype.windowHeight = function() {
    return Graphics.height;
};

//Draw picture function
Window_Worldtree.prototype.drawPicture = function(filename, x, y) {
    var bitmap = ImageManager.loadPicture(filename);
    this.contents.blt(bitmap, 0, 0, bitmap._canvas.width, bitmap._canvas.height, x, y);   
};
    
Window_Worldtree.prototype.refresh = function() {
    this.contents.clear();
    this.drawTextEx("Worldtree",0,0);
    this.drawPicture('worldtree',0,0);

};

Window_Worldtree.prototype.open = function() {
   this.refresh();
  Window_Base.prototype.open.call(this);
};
 

Poryg

Dark Lord of the Castle of Javascreeps
Veteran
Joined
Mar 23, 2017
Messages
4,125
Reaction score
10,639
First Language
Czech
Primarily Uses
RMMV
I see where the problem is.

Code:
Window_Worldtree.prototype = Object.create(Window_Base.prototype);
Window_Base doesn't have setHandler defined. setHandler is a prototype of Window_Selectable. So you need to set your window as a prototype of Window_Selectable.

Also, a couple of tips for cleaner code.
Code:
Worldtree_Scene.prototype.stop = function() {
   Scene_MenuBase.prototype.stop.call(this);
};
This is a totally pointless function. Since Worldtree_Scene is a prototype of Scene_MenuBase, it inherits every function from Scene_Menubase. So unless you want to change it, it's pointless to redefine it.

Code:
Worldtree_Scene.prototype.create = function() {
   Scene_MenuBase.prototype.create.call(this);
   this._worldtreeWindow = new Window_Worldtree(0,0);
   this._worldtreeWindow.setHandler('cancel', this.popScene.bind(this));
   this._worldtreeWindow.activate();
   this.addWindow(this._worldtreeWindow);
};
This is not a pointless function, because after it calls the parent function, it adds some information unique for itself.
 

ValiLey

Warper
Member
Joined
May 2, 2017
Messages
4
Reaction score
0
First Language
German
Primarily Uses
RMMV
I see, makes sense.
Didn't even know Window_Selectable existed xD

Thank you very much.
 

Poryg

Dark Lord of the Castle of Javascreeps
Veteran
Joined
Mar 23, 2017
Messages
4,125
Reaction score
10,639
First Language
Czech
Primarily Uses
RMMV
You'll learn a lot from reading the core scripts :D
 

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Profile Posts

Couple hours of work. Might use in my game as a secret find or something. Not sure. Fancy though no? :D
Holy stink, where have I been? Well, I started my temporary job this week. So less time to spend on game design... :(
Cartoonier cloud cover that better fits the art style, as well as (slightly) improved blending/fading... fading clouds when there are larger patterns is still somewhat abrupt for some reason.
Do you Find Tilesetting or Looking for Tilesets/Plugins more fun? Personally I like making my tileset for my Game (Cretaceous Park TM) xD
How many parameters is 'too many'??

Forum statistics

Threads
105,868
Messages
1,017,066
Members
137,576
Latest member
SadaSoda
Top