As a scripter, I write scripts with the goal of being plugged into any project and suddenly a developer has just solved a problem.
In this article I discuss a certain technique that I personally have not seen being used very often in RPG Maker scripts, though it is something I feel is extremely important for compatibility between scripts. Or Maybe I just don't look at enough scripts.
Object Composition
In software engineering, there is a concept called Object Composition. You can read about it on Wikipedia but basically you have an object that contains another object. Wikipedia uses the analogy of a car being composed of an engine, wheels, and all of the other parts that you may expect from a fantasy automobile, such as laser turret or warp drives.
Where would I use it?
In RPG Maker, you can see examples of object composition. A battler sprite holds a reference to the battler object that it represents. Similarly, a character sprite holds a reference to the character object that it represents.
Rather than creating a single object that handles both the logic (moving around, keeping track of HP and skills) as well as the presentation (updating animations, drawing the picture), we logically separate the two sets of responsibilities into their own classes, and use object composition to link them together. There is also something called MVC which appears to be useful but that's a different topic.
Revisiting Alias
Aliasing is a common technique that is used to increase compatibility between scripts. It is usually quite effective as well, since you are simply adding extra logic on top of existing code. However, there are times when aliasing is not the best solution.
For example, let's say you are writing a battle system that provides a number of mechanics such as battler positions on the battlefield as well as limiting your skills to the equips that you are currently holding. If you don't know what those mean, that's ok. Basically, you are going to have to add new logic to classes like `Game_Battler` and `Game_Unit`. Adding new attributes and changing the way skills are determined can be done using aliases, while allowing you to preserve existing logic that may have been added by other scripts.
Everyone shares everything
This is a consequence behind aliasing methods. When you add more logic to a method, everyone else now has to cope with it, even if you didn't intend it yourself.
This starts to become a problem when you have two or more scripts want to use the same method, but they will conflict with each other because the logic they're adding is not what the other scripts want.
Going with the example of battle skills, the default system makes it so that you can use basically any skill you want as long as the requirements are met. If I added logic to only limit it to skills that are associated with certain equips, this change may be incompatible with the default battle system (or even outside of battle, such as in the menu screen).
There are many ways to come up with a situation where two scripts aliasing the same method causes problems, and for sufficiently complex scripts such as battle systems, you will very likely have many conflicting methods. Aliasing in these situations is effective, but what could we do?
...
Read the rest at Hime Works!
In this article I discuss a certain technique that I personally have not seen being used very often in RPG Maker scripts, though it is something I feel is extremely important for compatibility between scripts. Or Maybe I just don't look at enough scripts.
Object Composition
In software engineering, there is a concept called Object Composition. You can read about it on Wikipedia but basically you have an object that contains another object. Wikipedia uses the analogy of a car being composed of an engine, wheels, and all of the other parts that you may expect from a fantasy automobile, such as laser turret or warp drives.
Where would I use it?
In RPG Maker, you can see examples of object composition. A battler sprite holds a reference to the battler object that it represents. Similarly, a character sprite holds a reference to the character object that it represents.
Rather than creating a single object that handles both the logic (moving around, keeping track of HP and skills) as well as the presentation (updating animations, drawing the picture), we logically separate the two sets of responsibilities into their own classes, and use object composition to link them together. There is also something called MVC which appears to be useful but that's a different topic.
Revisiting Alias
Aliasing is a common technique that is used to increase compatibility between scripts. It is usually quite effective as well, since you are simply adding extra logic on top of existing code. However, there are times when aliasing is not the best solution.
For example, let's say you are writing a battle system that provides a number of mechanics such as battler positions on the battlefield as well as limiting your skills to the equips that you are currently holding. If you don't know what those mean, that's ok. Basically, you are going to have to add new logic to classes like `Game_Battler` and `Game_Unit`. Adding new attributes and changing the way skills are determined can be done using aliases, while allowing you to preserve existing logic that may have been added by other scripts.
Everyone shares everything
This is a consequence behind aliasing methods. When you add more logic to a method, everyone else now has to cope with it, even if you didn't intend it yourself.
This starts to become a problem when you have two or more scripts want to use the same method, but they will conflict with each other because the logic they're adding is not what the other scripts want.
Going with the example of battle skills, the default system makes it so that you can use basically any skill you want as long as the requirements are met. If I added logic to only limit it to skills that are associated with certain equips, this change may be incompatible with the default battle system (or even outside of battle, such as in the menu screen).
There are many ways to come up with a situation where two scripts aliasing the same method causes problems, and for sufficiently complex scripts such as battle systems, you will very likely have many conflicting methods. Aliasing in these situations is effective, but what could we do?
...
Read the rest at Hime Works!
Last edited by a moderator:
