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

---
title: cvar
description: ConVar read and write access
icon: settings
---

The `cvar` namespace exposes the game's ConVars and ConCommands. Index `cvar` with a ConVar name to get a `cvar_object`, then read or write its value with the typed accessors below.

<Expandable title="Example">
  ```lua lines=false
  cvar.mp_teammates_are_enemies:int(1)
  cvar.clear:call()
  ```
</Expandable>

## call

```lua
cvar_object:call(...)
```

> Executes a ConCommand or cvar callback, passing its arguments to it.

<Schema title="Parameters">
  <SchemaField name="..." type="any">
    Arguments passed to the callback.
  </SchemaField>
</Schema>

## int

> Gets or sets the ConVar int value.

<Tabs>
  <Tab title="Get value">
    ```lua
    cvar_object:int(): number
    ```

    <Schema title="Returns">
      <SchemaField name="value" type="number">
        The current int value of the ConVar.
      </SchemaField>
    </Schema>
  </Tab>

  <Tab title="Set value">
    ```lua
    cvar_object:int(value: number[, raw: boolean])
    ```

    <Schema title="Parameters">
      <SchemaField name="value" type="number" required>
        New int value.
      </SchemaField>

      <SchemaField name="raw" type="boolean">
        Optional. If `true`, the raw value is set.
      </SchemaField>
    </Schema>
  </Tab>
</Tabs>

## float

> Gets or sets the ConVar float value.

<Tabs>
  <Tab title="Get value">
    ```lua
    cvar_object:float(): number
    ```

    <Schema title="Returns">
      <SchemaField name="value" type="number">
        The current float value of the ConVar.
      </SchemaField>
    </Schema>
  </Tab>

  <Tab title="Set value">
    ```lua
    cvar_object:float(value: number[, raw: boolean])
    ```

    <Schema title="Parameters">
      <SchemaField name="value" type="number" required>
        New float value.
      </SchemaField>

      <SchemaField name="raw" type="boolean">
        Optional. If `true`, the raw value is set.
      </SchemaField>
    </Schema>
  </Tab>
</Tabs>

## string

```lua
cvar_object:string([value: any]): string
```

> Gets or sets the ConVar string value.

<Schema title="Parameters">
  <SchemaField name="value" type="any">
    New string value. If omitted, returns the current string value of the ConVar.
  </SchemaField>
</Schema>

<Schema title="Returns">
  <SchemaField name="value" type="string">
    The string value of the ConVar.
  </SchemaField>
</Schema>

## set\_callback

```lua
cvar_object:set_callback(callback: function)
```

> Registers a callback for the specified ConVar/Command. The registered function is called every time the ConVar value updates.

<Schema title="Parameters">
  <SchemaField name="callback" type="function" required>
    Lua function to call.
  </SchemaField>
</Schema>

<Note>
  **ConVar callbacks** — access the `cvar_object`, `old_value`, and `new_value` by adding them to the function arguments.
</Note>

<Note>
  **Command callbacks** — access the `cvar_object` and `args` by adding them to the function arguments. Return `false` inside the callback to prevent the command from being executed.
</Note>

## unset\_callback

```lua
cvar_object:unset_callback(callback: function)
```

> Unregisters a callback that was set via `:set_callback` from the specified ConVar/Command.

<Schema title="Parameters">
  <SchemaField name="callback" type="function" required>
    The Lua function that was passed to `:set_callback`.
  </SchemaField>
</Schema>
