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. bool requires a boolean; int32 and float32 take a number or numeric string (int32 converts it to an integer); other values 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 and may change or drop it. A true result means the text was submitted.

Values must match the variable type: string or number where accepted, numbers converted to integers for the 16- and 32-bit integer types, and compatible colours, vectors or angles. 64-bit types take int64_t / uint64_t cdata or a whole number (negative only for int64); otherwise they raise integer, int64_t or uint64_t expected / non-negative integer, int64_t or uint64_t expected. Other 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