How do you write your compatibility code between scripts

Your script overwrites a method, but you find that someone else's script also overwrites the same method, and you want your script to be compatible with it.


What do you do?


I can't think of an example atm.
I often create new subclasses, that have the overwritten classes as parents - but in your subclass you can use its very own method even if it is overwritten in parent - Same method name but different content. Gosh I hope my english is understandable...
It depends on the default method definition and what additional functionality you would like to do implement on the said method. If the other scripter doesn't care about making the script compatible, usually they would redirect the flow from the default flow, then there's little to do to avoid clashing if your script depends on the default flow, I would just go and see what the other scripts are doing and try to think of a way to work together in that case.

Whenever I see 'super', I would just go for the Parent class and override it there though if the Parent class is one of the uncharted scripts, it could be a hit or miss, but because of that (uncharted thingy), scripters are less likely to touch them, which means compatibility would be pretty high. And then since you would like to work with the subclasses, in the parent class, I would create another method that pass the necessary argument(s) including self.class, and just put a check to receive the desired sub-class.

If there's no super, then TinyMine's concept could work. When overwriting method with no super I would suggest adding pre and post path after aliasing.

alias a_lias_method_test method_testdef method_test(*args) pre_a_lias_method_test(*args) a_lias_method_test(*args) post_a_lias_method_test(*args) endAnd you could tell the user to put your script lower than other script made by other scripters, but higher than the sub-script of yours since during overwriting without intense preparation, position matters. I would think a bit of how to make my script a bit compatible, but I have decided that I won't spend tons of time doing so, if there's incompatibility, then I'd have the user to report it back to me, and I'll maintain it from there. : D
For ACE, I'd just make a provision for the specific script directly within your overwrite and just make sure it is know to place your script lower. This is much less of an issue in ACE, where generally there is a method you can access for any given task, as it was in VX where frequently more than one simple task is performed in any given method, meaning that two people may want to overwrite the script for different reasons. In ACE, if both are overwriting the same method completely, it generally means that you are both attempting to do the same task differently and only one actually needs to be performed, in which case you need to decide which is more important (or if the scripts are fundamentally incompatible). In cases where you aren't attempting the same thing but both need to overwrite for some reason, you can handle on a case by case basis. The downside is that you actually need to read the method you are making provisions for. I can't think of a good example of this for ACE, either.


All this of course refers to only if both methods overwrite without using an alias. If this overwrite was actually necessary, then having your own subclass for your own namespace that invokes super or creating an alias are not valid solutions as they would both invoke code you have already decided you don't need, otherwise you wouldn't have completely overwritten to begin with. Subclassing works well if you need a new class that has most of the functions of its hierarchy (eg., a brand new window for your own custom scene that works kind of like Window_EquipItem, but want to overwrite a few functions), but poorly when you are modifying the behavior of classes that already create their own instances within the base code(would you really subclass Game_Actor to avoid overwriting code?)


If an alias is used in either and the other has preserved both arguments and return values, usually all that is needed is for the one that aliases to be lower on the list. If the arguments and return values have been changed, you'd need to make a specific provision for the script either way because it doesn't even do what you thought it was going to do anymore.

Original thread: https://forums.rpgmakerweb.com/threads/how-do-you-write-your-compatibility-code-between-scripts.22446/