FluxWareScripting
Back to site

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',
}
FieldMeaning
namestring, 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.
categorystring, required. One of: combat, movement, player, utility, render, crystal, misc.
One module per script
Calling 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, ...) -> Setting

Declares 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() -> boolean
m: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.

KindCall
booleanm:setting('boolean', name, default)
numberm:setting('number', name, default, min, max, [step])
rangem:setting('range', name, low, high, min, max, [step])
modem:setting('mode', name, {'A','B'}, [default])
stringm:setting('string', name, default)
colorm:setting('color', name, 0xAARRGGBB)
keym:setting('key', name, [glfwKeyCode])
labelm: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)