require
The require
function takes the path to one of your scripts and returns the cached return value of that script.
The path to a script is always calclated from the avatar.json
file, regardless of the location of the executing script. Additionally, the file path seperator is .
instead of /
and an extension of .lua
is assumed.
All scripts in an avatar will execute exactly once.
If you require
a script that has not executed yet, that script will execute. require
will then return the value that that script returned.
If you require
a script that has already executed, require
will return the value that the script originally returned without executing it again.
If a script returns nothing, require
will return true
.
If you try to require
a script that does not exist, it will error. This can be avoided by calling require
in pcall
, a base Lua function.
Examples
Script in root folder
MyCoolAvatar├─
script└─
JimmyAnims
-- script.lua
require("JimmyAnims")
Script in another folder
MyCoolAvatar├─
script└─
MyFolder └─
GSAnimBlend
-- script.lua
require("MyFolder.GSAnimBlend")