Orion Solutions Docs
ORION SOLUTIONS LUA API

CVar

Read, write and execute engine console variables and commands.

Example

print(cvar.sv_cheats:int())
print(cvar.cl_interp:float())

cvar.cl_interp:float(0.031)
cvar.clear:call()

Access a console variable or command dynamically through cvar.<name>. Unknown names return nil.

:call

cvar_object:call(...): boolean
NameTypeDescription
...anyArguments appended to the command before execution.

Executes a console command. Returns true when the resolved object is a command and could be submitted to the engine.

Example

cvar.clear:call()
cvar.say:call("Hello from Orion Solutions")

:int

cvar_object:int(): number
cvar_object:int(value: number)

Gets or sets the integer value of a ConVar.

Example

local value = cvar.sv_cheats:int()
print(value)

cvar.sv_cheats:int(0)

:float

cvar_object:float(): number
cvar_object:float(value: number)

Gets or sets the floating-point value of a ConVar.

Example

local old_value = cvar.cl_interp:float()

cvar.cl_interp:float(0.031)
print(cvar.cl_interp:float())

cvar.cl_interp:float(old_value)

:string

cvar_object:string(): string
cvar_object:string(value: string)

Gets or sets the string value of a ConVar.

Example

local name = cvar.name:string()
print(name)

cvar.name:string("Orion Solutions")

:set_callback

cvar_object:set_callback(callback: function): boolean
NameTypeDescription
callbackfunctionFunction called when the ConVar value changes.

Registers a callback owned by the current script. The callback receives the CVar object, the old string value and the new string value.

Example

local function on_change(object, old_value, new_value)
    print("Changed:", object.name)
    print("Old:", old_value)
    print("New:", new_value)
end

cvar.cl_interp:set_callback(on_change)

:unset_callback

cvar_object:unset_callback(callback: function): boolean
NameTypeDescription
callbackfunctionThe same Lua function previously passed to :set_callback.

Removes a previously registered callback from the ConVar.

Example

local function on_change(object, old_value, new_value)
    print(object.name, old_value, new_value)
end

cvar.cl_interp:set_callback(on_change)
cvar.cl_interp:unset_callback(on_change)
Script Cleanup

All CVar callbacks owned by a script are automatically removed when that script is unloaded. If a Lua CVar callback throws an error, Orion Solutions logs the error and unloads the owning script.