The different "Overwrite"

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~
I'm curious... in the second one, just adding a alias and adding the new thing would have been more efficient... right?
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 = [email hidden] = Cache.system("something" + index.to_s)@sprite.x = [email protected] = [email protected] = 30end#then I want to add a new feature to my method...def something @sprite = [email hidden] = Cache.system("something" + index.to_s)@sprite.x = [email protected] = [email protected] = [email hidden] = 300endwhy I would for just a little code ....using a alias when I can just overwrite it?
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.
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.
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
Well typically if your doing a full GUI no one is going to use a script that overwirtes it anyways. Usually.
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.
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.
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
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...
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:

Spoiler
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.
If you wan to marshal such an object you can still use extend here instead:

Spoiler
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>
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. 😀
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. 😀
haha I know sixth! but I wanted to show all the type of overwrite XD

Original thread: https://forums.rpgmakerweb.com/threads/the-different-overwrite.37569/