-
Notifications
You must be signed in to change notification settings - Fork 1
Lua Environment
This page describes available APIs and special methods you can implement in your init.lua
.
The following functions can be implement in your init.lua
and are called by the loader if they exist.
This function is called after all game classes have loaded.
Example (init.lua) |
---|
function ready()
-- code to run on ready
end |
This function is called when your mod is unloaded from the mod-manager.
You should clean up all changes your mod made to the game here.
Example (init.lua) |
---|
function unload()
-- restore any changes made to the game here
end |
It is recommended to make use of this function when implementing a mod that does not require a restart to be loaded/unloaded.
There is no special function that is called when the mod is loaded, instead all the code inside of the init.lua
that is not inside a function will be called.
Example (init.lua) |
---|
function ready()
-- not called on load
end
print("Im called on load!") |
The require()
call when used from a mod differs from lua's default implementation.
First off, all calls to require()
are partially sandboxed by default, meaning you can only require files that are in the same directory of the directory your init.lua
resides in.
Sub-Directories are also supported:
<mod-folder>/a/b.lua
would becomerequire('a.b')
.
In case you want to require files used by the game (i.e. classes.modules.interface.menuBuilder
) you should prefix the module name with :
.
Example |
---|
local menu_builder = require(":classes.modules.interface.menuBuilder") |
In some cases other mods might intercept your call to require the game file and modify it in such a way that you can't properly work with it.
To circumvent this, prefix the require with !
.
Example |
---|
local menu_builder = require(":!classes.modules.interface.menuBuilder") |
Some mods are "utility" mods, meaning they don't actively modify the game but are instead intended to be used by other mods.
In case you depend on such a mod, you can access it's files by writing your require as @<name>:<file>
.
|
|
---|---|
local T = {}
function T:some_util_func()
-- ...
end
return T |
local util = require("@util_mod:util")
util:some_util_func() |