Skip to content

Settings, input, and data

The three mechanisms serve different purposes:

Mechanism Use it for
Config Settings exposed in the module UI.
InputActions Buttons and other control actions.
Storage Internal local data across module activations.

config.json contains a JSON array:

[
{
"label": "Show status",
"key": "ShowStatus",
"type": "bool",
"value": true
},
{
"label": "Text size",
"key": "TextSize",
"type": "number",
"value": 18,
"min": 12,
"max": 32
}
]
if Config.ShowStatus then
ImGui:DrawText(
"Active",
Rect.new(20, 20, 180, 40),
Config.TextSize,
Color.new(1, 1, 1),
TextAnchor.MiddleLeft
)
end

Do not use Config as storage. The game repopulates the table with saved settings after a UI change.

inputs.json:

{
"Actions": [
{
"Name": "ToggleStatus",
"Type": "Button",
"Binding": {
"Path": "<Keyboard>/f8"
}
}
]
}

main.lua:

local action = InputActions:FindAction("ToggleStatus")
local visible = true
if action ~= nil then
action:OnPerformed(function()
visible = not visible
end)
end

Check for nil: a mismatched name or invalid action definition is not found.

if Storage.StatusVisible == nil then
Storage.StatusVisible = true
end
local visible = Storage.StatusVisible
local function Toggle()
visible = not visible
Storage.StatusVisible = visible
end

false is valid, so initialize with == nil rather than if not ....

Config, InputActions, and Storage are client concerns. The server receives its own Config when loaded but cannot see client input or Storage.

Send a small validated table through Network when the server needs current client state.

See Config, InputAction, and Storage for complete formats.