Skip to content

Console Settings

Needs the internal running and needs_internal = true in script_info.

convar.get(name)              -> seq | nil
convar.set_int(name, value)   -> seq | nil
convar.set_float(name, value) -> seq | nil
convar.set_bool(name, value)  -> seq | nil
convar.result(seq)            -> ok, float, int | nil

Reads and changes the settings you would type into the game's own console, such as fps_max.

The answer comes later

Every call returns a number, seq, straight away. The game handles the request on a later tick. Pass seq to convar.result to get the answer:

convar.result(seq) returnsMeaning
nilNot done yet. Ask again on the next tick
true, float, intDone. For convar.get, the value as a number and as a whole number
falseThe setting does not exist, or could not be changed

Only the most recent answers are kept, so read yours within a few ticks.

lua
script_info = { name = "read_fps_max", needs_internal = true }

local seq, done

function on_tick()
    if done then return end
    if not seq then
        seq = convar.get("fps_max")
        return
    end
    local ok, f, i = convar.result(seq)
    if ok == nil then return end   -- not done yet
    print(ok and ("fps_max is " .. i) or "no such setting")
    done = true
end

Changing a setting

convar.set_int needs a whole number: 144 works, 144.5 is an error. convar.set_bool takes true or false. convar.set_float takes any number.

lua
local seq = convar.set_int("fps_max", 240)

A change stays after your script stops. If your script changes a setting, change it back when you are done.

Returns nil when

  1. needs_internal = true is missing from script_info.
  2. The internal is not running.
  3. 16 requests are already waiting, across convar.* and chat.* together.

A name can be up to 63 characters.