Skip to main content
Read and write game console variables.
Overrides are restored when the script unloads, reloads, or is disabled. Full convar list - names, types, defaults and flags.

Find

Returns a ConVar, or nil if the name isn’t registered. Case-insensitive. cvar.viewmodel_fov does the same thing. Find, RestoreAll and the flag constants are real members of the table, so a convar sharing one of those names needs cvar.Find. Lookups are cached and case-insensitive. Store frequently used convars in locals:

Get

Returns the value in the convar’s own type. vector2 and vector4 have no userdata type of their own, so they read back as plain keyed tables and are written the same way.

Set

Takes the type returned by Get, with basic conversions:
Invalid conversions and failed overrides error. Vector and QAngle also accept plain tables. Color accepts a Color or packed 0xRRGGBBAA integer. Values are not clamped to cv.min or cv.max. Two scripts can hold the same convar. The last one to Set it owns the restore, so unloading it puts the engine value back even if another script wrote it first.

Restore

Restores the original value. RestoreAll restores every convar owned by the current script. Script unload and disable do this automatically. Restore errors if another script owns the override, and does nothing if nobody does.

Properties

Read-only. Assigning to one errors; use :Set.

Flags

FCVAR_CHEAT, FCVAR_REPLICATED, FCVAR_DEVELOPMENTONLY, FCVAR_REFERENCE, FCVAR_HIDDEN, FCVAR_PROTECTED, FCVAR_ARCHIVE, FCVAR_NOTIFY, FCVAR_USERINFO, FCVAR_PER_USER. For anything else test cv.flags against a literal. Use HasFlag for flags above bit 31 because LuaJIT’s bit library is 32-bit.

Limits

Writes do not fire change callbacks. Server convars work only when server.dll is running locally.
For commands with no value behind them, use engine.ExecuteCommand.