Persistent state
Goal: remember whether the HUD was hidden when the module was disabled normally.
if Storage.Layout == nil then Storage.Layout = { version = 1, visible = true }end
local Visible = Storage.Layout.visiblelocal ToggleAction = InputActions:FindAction("TogglePanel")
if ToggleAction ~= nil then ToggleAction:OnPerformed(function() Visible = not Visible Storage.Layout.visible = Visible end)end
Scheduler:OnFrame(function() if Visible then ImGui:DrawDebugText("Persistent panel") endend)false is not missing. Initialize the table only when Storage.Layout == nil.
Structure version
Section titled “Structure version”Perform a small migration when the format changes:
if Storage.Layout == nil or Storage.Layout.version ~= 2 then local oldVisible = true
if Storage.Layout ~= nil and Storage.Layout.visible ~= nil then oldVisible = Storage.Layout.visible end
Storage.Layout = { version = 2, visible = oldVisible, compact = false }endLimitations
Section titled “Limitations”- strings, numbers, booleans, and nested tables persist;
- split userdata such as
Vector3into numbers; - assigning
nilremoves a key after save; - hot reload does not serialize current state;
- test by disabling and enabling the module normally.
Reference: Storage, InputAction, and Vector3 for serializing structured values.