Dependencies
Description
Every class and helper has access to the following global variables:
Functions
A table with all predefined formula functions from the functions directory.
Classes
A table with all predefined functions from the classes directory that build metatables to simulate object oriented programming.
Helpers
A table with all predefined functions from the helpers directory that help reuse a block of code after defining it once.
These can be helpful when one function requires another.
Usage
Let's say you wanted to calculate an action's power based on a randomly selected character stat (e.g. strength or magick power). For that, you could write something like this:
local function getRandomStat(character)
local argBase = memory.getSymbol("tif_grn_args")
memory.execute("tif_grn_call")
local rndNum = memory.u32[argBase] % 2
if rndNum == 0 then
return character.strength
else
return character.magickPower
end
end
return getRandomStatNow the issue with this one is that you are redefining the getRandomNumber helper which is not really desirable as its rather redundant and also error prone. Instead of doing that, you can directly use the required function by accessing the global variable helpers like this:
Keep in mind that if getRandomStat requires getRandomNumber, then the latter must be placed higher than the former in helpers.lua as only then they are loaded in the proper order. The same goes for classes, assemblies, etc.
You can do the same with assemblies and call one with the other by referencing its symbol.
Let's say that every time the party is healed with the healAll function, you also want to refresh their stats. For that, you could do the following:
Notes
A class, helper or assembly cannot require another which also requires it in return as that would result in a dependency loop.
Last updated