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 getRandomStat
Now 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:
local function getRandomStat(character)
local rndNum = helpers.getRandomNumber(2)
if rndNum == 0 then
return character.strength
else
return character.magickPower
end
end
return getRandomStat
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:
local assembly =
[[
tif_ha_call:
push rbx
sub rsp,0x20
mov edx,0000000F ;hp, mp, mist, negative status effects
call 0x0030F4B0 ;healall(unused, flags)
xor ebx,ebx
tif_ha_loop:
mov ecx,ebx
call 0x00320A40 ;getBattleUnitKeep
lea rdx,[%tif_rs_args%] ;refresh stats args
mov [rdx],rax
call %tif_rs_call% ;refresh stats call
inc ebx
cmp ebx,0x27
jna short tif_ha_loop
add rsp,0x20
pop rbx
ret
]]
...
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