Loops
General
There are several ways to loop through flags (e.g. formula.target.statusEffects
)
Let's say you wanted to create a formula function that doubles the formula's power for every status effect the target has. To do that, you could write something like this:
Now let's exclude the status effects protect
and shell
as another requirement. Since you have access to the status effect identifiers, you can easily add them to the current condition.
As the next step, you could expect the caster to also have the same status effects. There are multiple ways to accomplish this, some a bit more readable than others.
For example, instead of looping through the status effects table, you could also loop through the status effect bits table directly. That way you have access to not only a status effect's identifier, but also its name.
The flags here are accessed via different ways for demonstration purposes. You can choose whichever way suits your coding style more.
Notes
All entries in a metatable (list, flags, ...) start with 0, not 1. This is intended as that way the table key (e.g. 0
-> KO
) is identical to the identifier used by the game.
Due to technical limitations, you cannot loop through a metatable (list, flags, ...) via the ipairs function. Instead, you can use the pair function, or loop through it manually via its length.
Last updated