checkbox
A standard toggle widget used to switch between “on” and “off” states.
Signature
Section titled “Signature”-- using a standard booleanlocal newValue, changed = ui.checkbox(label, currentState)
-- using a refbool (recommended)local changed = ui.checkbox(label, myRefBool)Description
Section titled “Description”The checkbox displays a label alongside a square box that shows a checkmark when the value is true.
CSP provides two ways to handle state with this widget:
- Standard: Pass a boolean. The function returns the new state and a boolean indicating if it changed.
- Reference: Pass a
refbool. The function updates therefbooldirectly and returnstrueif the user clicked it.
Parameters
Section titled “Parameters”| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
label | string | Yes | - | Label text. |
value | boolean or refbool | Yes | - | The current state of the toggle. |
Return Values
Section titled “Return Values”| Type | Description |
|---|---|
boolean | Returns true if the state was toggled this frame. |
boolean | (Only if passing standard boolean) The new state of the checkbox. |
Examples
Section titled “Examples”The most efficient way to manage state in CSP.
local showDebug = refbool(false)
function script.windowMain() if ui.checkbox("Show Debug Info", showDebug) then ac.log("Toggle clicked! New state: " .. tostring(showDebug.value)) endendManual state management.
local myState = false
function script.windowMain() local newState, changed = ui.checkbox("Toggle Me", myState)
if changed then myState = newState endend