Skip to Content

console.variable

Console variable handle returned by console.<name> and console.variables(): reading and setting values.


Returned by console.<name> and console.variables(). Methods use :. Handles may be retained; unregistered variables are detected on access.

MethodReturns
cv:name()Name, or nil after unregistration.
cv:description()Help text or nil.
cv:flags()uint64_t or nil.
cv:get()Converted value or nil; see below.
cv:set(value)true, or nil, reason; see below.
tostring(cv)console.variable<name>.

Reading values

Variable typeLua result
boolboolean
int16, uint16, int32, uint32, float32, float64number
int64, uint64Corresponding 64-bit cdata
stringstring
colorFFI color
Vector, angle and other typesnil

Setting values

For bool, int32 and float32, assignment is immediate. Values must be boolean, integer and number respectively; mismatches raise. The value is clamped to the variable's range and change callbacks run. A true result does not guarantee the game accepted the value unchanged.

For other supported types, assignment queues name "value" in the command buffer and applies on the next frame. string_cmd receives it. A true result means the text was queued.

Values must match the variable type: string or number where accepted, whole integers for integer types, corresponding cdata for 64-bit types, and compatible colours, vectors or angles. Type mismatches raise. Vector-world variables raise unsupported variable type.

Text containing ", ;, CR, LF or NUL returns nil, "value cannot be quoted for the console". An unregistered variable returns nil, "cvar is no longer registered".

On this page