Skip to content

checkbox

A standard toggle widget used to switch between “on” and “off” states.

-- using a standard boolean
local newValue, changed = ui.checkbox(label, currentState)
-- using a refbool (recommended)
local changed = ui.checkbox(label, myRefBool)

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:

  1. Standard: Pass a boolean. The function returns the new state and a boolean indicating if it changed.
  2. Reference: Pass a refbool. The function updates the refbool directly and returns true if the user clicked it.
ParameterTypeRequiredDefaultDescription
labelstringYes-Label text.
valueboolean or refboolYes-The current state of the toggle.
TypeDescription
booleanReturns true if the state was toggled this frame.
boolean(Only if passing standard boolean) The new state of the checkbox.

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))
end
end