Can we alias something non existent in the subclass?

Milena

The woman of many questions
Veteran
Joined
Jan 26, 2014
Messages
1,281
Reaction score
106
First Language
Irish
Primarily Uses
N/A
I noticed that some subclasses do not have functions that were inherited from the parent class.

Scene_Menu for example, does not have an update, but Scene_MenuBase does. Can I create something like:

var alias_scene_menu_update = Scene_Menu.prototype.update;Scene_Menu.prototype.update = function() { alias_scene_menu_update.call(this);}even if Scene_Menu.prototype.update never existent since its a subclass of Scene_MenuBase?
 

Hudell

Dog Lord
Veteran
Joined
Oct 2, 2014
Messages
3,545
Reaction score
3,715
First Language
Java's Crypt
Primarily Uses
RMMZ
Instead of aliasing it, you create the method and call the parent:

Code:
Scene_Menu.prototype.update = function() {  Scene_MenuBase.prototype.update.call(this);}
 

Milena

The woman of many questions
Veteran
Joined
Jan 26, 2014
Messages
1,281
Reaction score
106
First Language
Irish
Primarily Uses
N/A
Thanks! Is this similar to super in RMVXAce?
 

Hudell

Dog Lord
Veteran
Joined
Oct 2, 2014
Messages
3,545
Reaction score
3,715
First Language
Java's Crypt
Primarily Uses
RMMZ
Not exactly. In JS, we are creating a new method and then calling the old one.

In ruby, the two methods are technically the same.
 

DarknessFalls

Rpg Maker Jesus - JS Dev.
Veteran
Joined
Jun 7, 2013
Messages
1,393
Reaction score
210
First Language
English
make sure the parent of the class your sub classing doesn't have said method. because if you do:

parent (has method) -> child (doesn't have method) -> grand child (create method) you are over riding the parent method.
 

Milena

The woman of many questions
Veteran
Joined
Jan 26, 2014
Messages
1,281
Reaction score
106
First Language
Irish
Primarily Uses
N/A
Not exactly. In JS, we are creating a new method and then calling the old one.

In ruby, the two methods are technically the same.
I see, I thought it was the same, thanks for the info.

make sure the parent of the class your sub classing doesn't have said method. because if you do:

parent (has method) -> child (doesn't have method) -> grand child (create method) you are over riding the parent method.
Thanks. I think I need to read more of this before continuing what I was coding, its a big help. :)
 

Tsukihime

Veteran
Veteran
Joined
Jun 30, 2012
Messages
8,564
Reaction score
3,846
First Language
English
I noticed that some subclasses do not have functions that were inherited from the parent class.

Scene_Menu for example, does not have an update, but Scene_MenuBase does. Can I create something like:

var alias_scene_menu_update = Scene_Menu.prototype.update;Scene_Menu.prototype.update = function() { alias_scene_menu_update.call(this);}even if Scene_Menu.prototype.update never existent since its a subclass of Scene_MenuBase?
This should work.

Scene_Menu.prototype.update would check its own definitions, and if it can't find it, it'll go up to its parent.

You can verify this in the console:

> Scene_Menu.prototype.updatefunction () { this.updateFade(); this.updateChildren(); AudioManager.checkErrors();}> Scene_MenuBase.prototype.updatefunction () { this.updateFade(); this.updateChildren(); AudioManager.checkErrors();}
make sure the parent of the class your sub classing doesn't have said method. because if you do:

parent (has method) -> child (doesn't have method) -> grand child (create method) you are over riding the parent method.
Wouldn't child also have the method by inheritance?
 
Last edited by a moderator:

DarknessFalls

Rpg Maker Jesus - JS Dev.
Veteran
Joined
Jun 7, 2013
Messages
1,393
Reaction score
210
First Language
English
Wouldn't child also have the method by inheritance?
yes. How ever most people when they alias a method or look for a method on a class, they might not see that "hey this class extends another class." Its rare, but it does happen.
 

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

Latest Threads

Latest Posts

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,862
Messages
1,017,045
Members
137,569
Latest member
Shtelsky
Top