> Agent-readable docs index: /llms.txt. Download /docs.zip to grep all markdown files locally.

---
title: Console Data
icon: terminal
sidebar_position: 5
---

# Console Data

The Convars and Commands pages list Source 2 console entries. In Lua, the
[`console`](/cs2/api_reference/engine/console) namespace looks them up by name.

## Read a convar

Console variables are exposed as objects with fields such as `name`, `help`,
`flags`, `value`, `default`, `min`, `max`, and `type`.

```lua luaintelligence=true lines=false semantic="lua:cs2:cs2/dumped_data/overview/console-data:0:7456a862ccd0"
local var = console.sv_cheats

if var.is_valid then
    print(var.name)
    print(var.value)
    print(var.default)
    print(var.help)
end
```

The `value` field is typed according to the engine convar type. It may be a
boolean, integer, number, string, `Color`, `Vector`, `Vector2D`, `Vector4D`, or
`QAngle`.

## Change a convar carefully

If your script changes a convar, store the old value and restore it on shutdown.

```lua luaintelligence=true lines=false semantic="lua:cs2:cs2/dumped_data/overview/console-data:1:d16d3755b4c1"
local showfps = console.cl_showfps
if showfps.is_valid then
    local old_showfps = showfps.value
    showfps.value = 1

    events.shutdown(function()
        if showfps.is_valid then
            showfps.value = old_showfps
        end
    end)
end
```

<Warning>
  Avoid changing convars every frame. Set them when a UI option changes, then restore anything temporary in `events.shutdown`.
</Warning>

## Commands

Console commands are callable objects. Check that the object is valid before
calling it, and avoid commands with obvious side effects unless the user
explicitly enabled that behavior in your script.

```lua luaintelligence=true lines=false semantic="lua:cs2:cs2/dumped_data/overview/console-data:2:88f8e843ae1a"
local clear = console.clear

if clear.is_valid then
    clear()
end
```

## Use Dumped Data for discovery

The console dump is useful when you do not know the exact name yet.

<Steps>
  <Step title="Search by keyword" icon="search">
    Use the Convars or Commands pages to search names and help text.
  </Step>

  <Step title="Check the type" icon="variable">
    The dump shows whether a variable is numeric, string-like, vector-like, or another supported type.
  </Step>

  <Step title="Check range and default" icon="sliders">
    `min`, `max`, and `default` tell you what values are reasonable before you write from Lua.
  </Step>

  <Step title="Use console.NAME" icon="terminal">
    Once you know the exact name, read it from the `console` namespace in your script.
  </Step>
</Steps>

<CardGroup cols={2}>
  <Card title="Convars" icon="sliders" href="/cs2/dumped_data/console/variables" arrow>
    Browse current console variables.
  </Card>

  <Card title="Commands" icon="terminal" href="/cs2/dumped_data/console/commands" arrow>
    Browse callable console commands.
  </Card>
</CardGroup>
