Classes
Description
Classes are metatables that simulate object oriented programming to help with creating easily readable and maintainable code in formula functions.
Every class is defined in a separate file, has a unique name, and is located in the classes
directory.
The classes.lua
file contains a list of all classes and in which order they will be loaded (higher first). The latter is important in cases where one requires another.
Layout
The former file returns a function that builds a metatable.
The latter file returns a table with every class. The value of a table entry equals the filename of the class (e.g. getBattleUnitWork
).
Usage
Let's say you wanted to create a formula function that doubles the damage the target receives if the caster catches them by surprise. Now, one way to do this would be to check whether the target is in a battle stance and if not, double the damage.
This is how the code would look without classes (partially):
and this with classes:
As you can see, if you do not use classes, you will have to manually get value of the battle stance flag via the base address and the battle flags offset (which is 0x00
in this case).
On the other hand, with classes, you can simply access that property of the structure directly. Not to mention that you won't have to remember or look up the address or offsets of hundreds of properties every time you use them.
In the background, the work required to get the result is of course still the same. You just have to write less to get what you want.
This is extremely helpful, even when working on basic tasks such as setting the caster's hp, level, etc. for some calculation. Without classes, you would have to constantly manually read from and write to memory.
Expansion
You can modify existing classes created by me and add entirely new ones if you want. However, this is more on the advanced side of modding, so unless you really know what you are doing, I would avoid messing with it. In almost all cases, I will have already provided all necessary properties for a class. The option is just there in case you really want to create your own.
Last updated