module{}
The only global constructor, and a script must call it exactly once. Everything else hangs off the handle it returns.
Declaring a module
local m = module {
name = 'Low Health Warning',
category = 'render',
}| Field | Meaning |
|---|---|
| name | string, required. Shown in the module list, and the key this module's settings are saved under, so changing it in a published update resets everyone's settings for it. |
| category | string, required. One of: combat, movement, player, utility, render, crystal, misc. |
module{} twice is an error. The one-to-one mapping between a slug, a marketplace entry and a row in the module list is what makes installing and uninstalling unambiguous.Methods
Everything hangs off the handle module{} returns. All of these are called with a colon.
m:setting(kind, name, ...) -> SettingDeclares a setting, backed by the client's own widgets, so it renders and persists exactly like a built-in module's. Must be called from the script body, not from a callback.
m:on(event, fn)Subscribes to an event. A second call for the same event REPLACES the handler rather than stacking, which is what makes reload and repeated toggling safe.
m:isEnabled() -> booleanm:toggle([state:boolean])With no argument, flips.
Setting kinds
Settings must be declared in the script body, not from inside a callback: the module's settings panel is built once, when the script loads.
| Kind | Call |
|---|---|
| boolean | m:setting('boolean', name, default) |
| number | m:setting('number', name, default, min, max, [step]) |
| range | m:setting('range', name, low, high, min, max, [step]) |
| mode | m:setting('mode', name, {'A','B'}, [default]) |
| string | m:setting('string', name, default) |
| color | m:setting('color', name, 0xAARRGGBB) |
| key | m:setting('key', name, [glfwKeyCode]) |
| label | m:setting('label', name, text) |
Every kind returns a handle with :get() and :set(value). A range returns two values from :get() and takes two in :set(). Handles are also reachable as m.settings[name].
local speed = m:setting('number', 'Speed', 1.2, 0.5, 3)
local colour = m:setting('color', 'Tint', 0xFF2563EB)
local reach = m:setting('range', 'Reach', 3, 4.5, 0, 6)
m:on('render2d', function()
local low, high = reach:get()
render2d.text(('%.1f - %.1f'):format(low, high), 4, 4, 9, colour:get())
end)