The different "Overwrite"

nio kasgami

VampCat
Veteran
Joined
May 21, 2013
Messages
8,949
Reaction score
3,042
First Language
French
Primarily Uses
RMMV
Hi guys I am here again for open a conversation about the overwriting!

so if we begin we all know overwriting is simply well redefine a existent method!

but I noticed they have multiple type overwriting so let's show what I know about them

Total Overwrite 

This one is the more common overwrite method we actually know that's the true term of "overwrite". Where we totaly change the ORIGINAL Parent method. 

E.g

# ORIGINAL ONE!class Window_Base < Window  #--------------------------------------------------------------------------  # * Get Standard Padding Size  #--------------------------------------------------------------------------  def standard_padding    return 12  endend# OVERWRITED ONE! class Window_Base < Window #-------------------------------------------------------------------------- # * Get Standard Padding Size #-------------------------------------------------------------------------- def standard_padding return Graphics.height unless contents < 4 #EXAMPLE DO NOT TRY THIS NOT WORK! endendPartial Overwrite

that's also a common in rgss who have the objective to not redefine TOTALLY the method but have the goal to just add your own little code without destroying the normal code

E.g

# ORIGINAL ONE!class Scene_Base#-------------------------------------------------------------------------- # * Termination Processing #-------------------------------------------------------------------------- def terminate Graphics.freeze dispose_all_windows dispose_main_viewport endend# OVERWRITED ONE! class Scene_Base#-------------------------------------------------------------------------- # * Termination Processing #-------------------------------------------------------------------------- def terminate Graphics.freeze dispose_all_windows dispose_main_viewport dispose_system endendthen  you also have

Localised Overwrite

this way is use for overwrite a PARENT method inside of a other script! (and will only affect the said script!)

E.g

class Scene_Base #-------------------------------------------------------------------------- # * Get Transition Speed #-------------------------------------------------------------------------- def transition_speed return 10 endendclass Scene_Title < Scene_Base #-------------------------------------------------------------------------- # * Get Transition Speed #-------------------------------------------------------------------------- def transition_speed return frame.rate + time #PURELLY A EXEMPLE NOT WORKING endendand they are! 

I hope you will enjoy to read this if I forgot anything don't hesit to tell it I am not a master and I don't know everything in the coding!

so 

Nio out~
 
Last edited by a moderator:

nio kasgami

VampCat
Veteran
Joined
May 21, 2013
Messages
8,949
Reaction score
3,042
First Language
French
Primarily Uses
RMMV
I'm curious... in the second one, just adding a alias and adding the new thing would have been more efficient... right?
in some case yes but I guess this a taste opinion but a lot of script need to modify some little part of the original code without changing it how I can explain it...

#Example my original method is thatdef something @sprite = Sprite.new@sprite.bitmap = Cache.system("something" + index.to_s)@sprite.x = 100@sprite.y = 200@sprite.z = 30end#then I want to add a new feature to my method...def something @sprite = Sprite.new@sprite.bitmap = Cache.system("something" + index.to_s)@sprite.x = 100@sprite.y = 200@sprite.z = 30@sprite.angle = 300endwhy I would for just a little code ....using a alias when I can just overwrite it?
 

DoubleX

Just a nameless weakling
Veteran
Joined
Jan 2, 2014
Messages
1,787
Reaction score
939
First Language
Chinese
Primarily Uses
N/A
I'd say it depends on actual cases. But in general, if you're almost 100% sure no one else gonna alias or rewrite the original method, then I think overwriting is ok(it also reduces the number of method calls by 1, so aliasing here may reduce the performance a bit), otherwise you may want to alias instead to reduce the chance of breaking someone else's code, if you value the compatibility of your scripts.
 

Bloodmorphed

Dungeon Fanatic
Veteran
Joined
Sep 17, 2012
Messages
1,466
Reaction score
144
First Language
English
Primarily Uses
No I get what you mean, but the example you have showed was a bit weird I guess.

I know it depends, and in this case I suppose it wouldn't matter much because if you change too much of the Scene_Base your most likely working on your own GUI, would mean you don't need to alias it, as your would be completely overwriting most things. Somewhat, anyways.
 

nio kasgami

VampCat
Veteran
Joined
May 21, 2013
Messages
8,949
Reaction score
3,042
First Language
French
Primarily Uses
RMMV
No I get what you mean, but the example you have showed was a bit weird I guess.

I know it depends, and in this case I suppose it wouldn't matter much because if you change too much of the Scene_Base your most likely working on your own GUI, would mean you don't need to alias it, as your would be completely overwriting most things. Somewhat, anyways.
lol yeah this was not the best of the example haha...but this the first who come to my mind haha

but I would avoid to overwrite to much like double_X said you need to be sure the method you overwrite will be not overwrite by other in simple
 

Bloodmorphed

Dungeon Fanatic
Veteran
Joined
Sep 17, 2012
Messages
1,466
Reaction score
144
First Language
English
Primarily Uses
Well typically if your doing a full GUI no one is going to use a script that overwirtes it anyways. Usually.
 

Tsukihime

Veteran
Veteran
Joined
Jun 30, 2012
Messages
8,564
Reaction score
3,846
First Language
English
in some case yes but I guess this a taste opinion but a lot of script need to modify some little part of the original code without changing it how I can explain it...


why I would for just a little code ....using a alias when I can just overwrite it?
Because if two people thought the same way, one script would lose out in the end.
 

Wavelength

MSD Strong
Global Mod
Joined
Jul 22, 2014
Messages
5,624
Reaction score
5,104
First Language
English
Primarily Uses
RMVXA
I alias (rather than using the "partial overwrite") whenever possible, even when it's something I'm sure other people won't try overwriting - because I like to organize my scripting into different pages in the editor.  If I want to add Function C to make_damage_value (which by default, say, does Function A and Function B ) for one purpose, and Function D for another purpose, I will alias the method twice: once for C and once for D.  I could just overwrite it once and include A, B, C, and D... but that gets messy if I want to transfer one of the additional functions to a new project.
 
Last edited by a moderator:

Solistra

Veteran
Veteran
Joined
Aug 15, 2012
Messages
593
Reaction score
247
Primarily Uses
Don't forget that you can also overwrite methods for specific objects via their singleton class (assuming you don't need to load or dump the object via Marshal):

Code:
str = 'I am a string.'class << str  def inspect() reverse endendp str # .gnirts a ma I
 

nio kasgami

VampCat
Veteran
Joined
May 21, 2013
Messages
8,949
Reaction score
3,042
First Language
French
Primarily Uses
RMMV
Don't forget that you can also overwrite methods for specific objects via their singleton class (assuming you don't need to load or dump the object via Marshal):

str = 'I am a string.'class << str  def inspect() reverse endendp str # .gnirts a ma I
oh my that's a really curious overwriting : D 

but I am not sure of what this make actually...
 

DoubleX

Just a nameless weakling
Veteran
Joined
Jan 2, 2014
Messages
1,787
Reaction score
939
First Language
Chinese
Primarily Uses
N/A
oh my that's a really curious overwriting : D 

but I am not sure of what this make actually...
My wild guess is that that overwrite affects the str object only, so if my wild guess's right:

Code:
str1 = 'I am a string.'str2 = 'I am a string.'class << str1  def inspect() reverse endendp str1 # .gnirts a ma Ip str2 # I am a string.
 

Another Fen

Veteran
Veteran
Joined
Jan 23, 2013
Messages
564
Reaction score
275
First Language
German
Primarily Uses
If you wan to marshal such an object you can still use extend here instead:

Code:
module Obscurred_Inspect   def inspect    super.reverse  endend str1 = "I'm a String"str2 = "I'm a String too"str3 = "I'm not quite sure"str1.extend(Obscurred_Inspect)def str3.inspect  super.reverseend p str1                              # "gnirtS a m'I"p Marshal.load(Marshal.dump(str1))  # "gnirtS a m'I"p str2                              # "I'm a String too"p str3                              # "erus etiuq ton m'I"p Marshal.load(Marshal.dump(str3))  # <Error>
 
Last edited by a moderator:

Sixth

Veteran
Veteran
Joined
Jul 4, 2014
Messages
2,162
Reaction score
822
First Language
Hungarian
Primarily Uses
RMVXA
The 2nd example is a waste of compatibility.


Use alias whenever you can. Why wouldn't you want your scripts to work with others?


If you have a method where you need to add something in the middle of the method, so not at the start or at the end of it, than overwriting is necessary. But if you want to just add something at the end or at the beginning, always use alias.


Making battle HUDs is indeed a perfect example where a LOT of overwrites are needed for sure. I just made one for a commission. :D
 

nio kasgami

VampCat
Veteran
Joined
May 21, 2013
Messages
8,949
Reaction score
3,042
First Language
French
Primarily Uses
RMMV
The 2nd example is a waste of compatibility.

Use alias whenever you can. Why wouldn't you want your scripts to work with others?

If you have a method where you need to add something in the middle of the method, so not at the start or at the end of it, than overwriting is necessary. But if you want to just add something at the end or at the beginning, always use alias.

Making battle HUDs is indeed a perfect example where a LOT of overwrites are needed for sure. I just made one for a commission. :D
haha I know sixth! but I wanted to show all the type of overwrite XD
 

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

Latest Threads

Latest Posts

Latest Profile Posts

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'??
Yay, now back in action Happy Christmas time, coming back!






Back in action to develop the indie game that has been long overdue... Final Fallacy. A game that keeps on giving! The development never ends as the developer thinks to be the smart cookie by coming back and beginning by saying... "Oh bother, this indie game has been long overdue..." How could one resist such? No-one c

Forum statistics

Threads
105,857
Messages
1,017,018
Members
137,563
Latest member
MinyakaAeon
Top