> ## Documentation Index
> Fetch the complete documentation index at: https://docs.spurdoverse.app/llms.txt
> Use this file to discover all available pages before exploring further.

# Convars

> Read console variables by name, typed.

Reads engine console variables by exact name.

```ts theme={null}
import convars from "@native/convars";
```

***

## Reading

### get

<br />

```ts theme={null}
convars.get(name: string): ConvarValue | null
```

The value in its natural type, or `null` when the convar doesn't exist.

| Convar type | Value |
| :- | :- |
| `bool` | `boolean` |
| `int16` `uint16` `int32` `uint32` `float32` `float64` | `number` |
| `int64` `uint64` | `bigint` |
| `string` | `string` |
| `color` | [Color](/api/types/color) |
| `vector2`, `vector3`, `qangle` | [Vector2](/api/types/vector2), [Vector](/api/types/vector), [QAngle](/api/types/qangle) |
| `vector4` | `[x, y, z, w]` |

```ts theme={null}
const cheats = convars.get("sv_cheats");   // boolean | null
```

### typeOf

<br />

```ts theme={null}
convars.typeOf(name: string): ConvarType | null
```

The convar's engine type from the table above, or `null` when it doesn't exist.

```ts theme={null}
convars.typeOf("sensitivity");   // "float32"
```

### Typed getters

<br />

```ts theme={null}
convars.getBool(name: string): boolean | null
convars.getInt(name: string): number | null
convars.getFloat(name: string): number | null
convars.getString(name: string): string | null
```

`null` when the convar doesn't exist. Numeric and bool convars convert between each other (`getInt` truncates);
asking a string convar for a number, or a number convar for a string, throws `TypeError`.

```ts theme={null}
const sens = convars.getFloat("sensitivity") ?? 1;
const yaw = convars.getFloat("m_yaw") ?? 0.022;
const degreesPerCount = sens * yaw;
```

***

## Example

Mouse counts needed to turn a given angle, for input code that moves the mouse.

```ts theme={null}
import convars from "@native/convars";

function countsFor(degrees: number): number | null {
    const sens = convars.getFloat("sensitivity");
    const yaw = convars.getFloat("m_yaw");
    if (sens === null || yaw === null || sens === 0) return null;
    return Math.round(degrees / (sens * yaw));
}

on("keydown", (e) => {
    if (e.code !== "F8") return;
    console.log("180° =", countsFor(180), "counts");
    console.log("zoom ratio:", convars.getFloat("zoom_sensitivity_ratio"));
});
```
