# Variables and collections

> Store single values in variables and tables of rows in collections.

Source: https://docs.buildcord.dev/concepts/data/

A bot's data lives in the data store, not in the blueprint. The blueprint only declares what exists.

## Variables

A *variable* holds one value. It has a name, a type, a scope and a default.

**Types:** text, number, boolean and list.

**Scopes** decide whose value it is:

| Scope | One value for each |
| --- | --- |
| Global | Bot |
| Server | Server |
| Member | Member of a server |
| User | Discord user, across servers |

Read a variable with `{var.name}`, such as `{var.points}`. Change it with [Set variable](https://docs.buildcord.dev/nodes/variables-and-data/set-variable), [Change a number](https://docs.buildcord.dev/nodes/variables-and-data/change-number) or [Run equation on variable](https://docs.buildcord.dev/nodes/variables-and-data/run-equation). Clear it with [Delete variable](https://docs.buildcord.dev/nodes/variables-and-data/delete-variable).

For a value that matters only during one run, use [Set a unique variable](https://docs.buildcord.dev/nodes/variables-and-data/unique-variable), which you read as `{temp.name}`.

## Collections

A *collection* is a table. It has named columns, and each column is **text**, **number**, **boolean**, **user** or **date**. Each row gets a number, available as `{row.id}`.

Use collections for lists that grow, such as tickets, suggestions, giveaway entries or balances.

| To | Use |
| --- | --- |
| Look rows up | [Find rows](https://docs.buildcord.dev/nodes/variables-and-data/find-rows) |
| Repeat steps for each row | [For each row](https://docs.buildcord.dev/nodes/variables-and-data/for-each-row) |
| Add a row | [Add row](https://docs.buildcord.dev/nodes/variables-and-data/add-row) |
| Change rows | [Change rows](https://docs.buildcord.dev/nodes/variables-and-data/change-rows) |
| Remove rows | [Delete rows](https://docs.buildcord.dev/nodes/variables-and-data/delete-rows) |

### Conditions

Steps that look rows up take a **Where** condition. Compare a column with `=`, `!=`, `<`, `<=`, `>` or `>=`, and join several with `and`. An empty condition matches every row.

```text
user = {user.id} and status = open
```

### Sorting

**Sorted by** takes a column, then `desc` for largest first. Left empty, the oldest rows come first.

```text
score desc
```

### Avoiding races

Two runs can read the same row at the same moment. To keep both from acting on stale data, either use **Add to** in [Change rows](https://docs.buildcord.dev/nodes/variables-and-data/change-rows), which counts both runs, or put [One run at a time](https://docs.buildcord.dev/nodes/variables-and-data/one-run-at-a-time) before the read.
