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

# Use variables in blocks

> Show a variable, save something in it, add to it, check it and reset it.

You made a variable. Now let's **use** it. There are five things you can do with a variable:

| I want to... | Use this |
| - | - |
| **Show** what's inside | Type `{DBVAR_name}` in any message |
| **Put** something in it | The **Save a value** block |
| **Add or take away** | The **Do the maths** block |
| **Check** what's inside | The **Compare** check |
| **Empty** it | The **Clear a value** block |

You find the blocks in the builder's blocks tab, under **Steps**, in the **Saved values** group. **Compare** is in the **Checks** tab. You can also type a block's name into the block search.

## 1. Show what's inside

Type the tag anywhere you can type: a reply, an embed, a layout message, a button label, an image card, a channel name, and most block settings.

```text theme={null}
You have {DBVAR_coins} coins!
```

For a **User** variable, this shows the value of **the person who used the command** (or the person the event is about).

### The easy way: don't type it, insert it

Typing brackets by hand can go wrong. One missing letter and it does not work. So use the buttons instead:

* Next to text boxes in the builder there is a `{ }` **Variables** button. Press it, find your variable and press it. It is put into the box for you.
* In a **Layout message**, the **Insert a variable** button puts the variable exactly where your cursor is.
* In **Card Studio**, use the **insert a value** button next to each text.
* On the **Database** page, press the gold `{DBVAR_...}` chip to **copy** it, then paste it.

The picker only shows values that work in the place you are building. A WhatsApp flow, for example, never shows Discord values.

### Backup values

Sometimes a box is **empty**. Then your message could look broken, like `Hi !`. Give the variable a **backup**: write a straight line `|` after the name, then the backup text.

```text theme={null}
You have {DBVAR_coins|0} coins.
```

| You write | If the value is empty, the bot shows |
| - | - |
| `{DBVAR_coins\|0}` | `0` |
| `{DBVAR_bio\|No bio yet}` | `No bio yet` |
| `Hi {user_name\|friend}!` | `Hi friend!` |

Backups work in Discord commands, Discord events and WhatsApp flows, and the chat preview in the builder shows them too.

> [!WARNING]
>
> **Secrets** never use a backup. If a secret is missing, it stays missing, so a wrong password is never sent by accident.

## How to target someone else

By default a User variable shows **the person who used the command**. To show **someone else's** value, add the person in **square brackets** right after the name.

With a member input called `user`:

```text theme={null}
{DBVAR_coins[option_user]} coins
```

Inside the brackets you can put a **user ID**, a **mention**, or **another variable**.

> **Someone's coins**
>
> `/balance @Alex`
>
> `{user_name[option_user]} has {DBVAR_coins[option_user]} coins.`
>
> Bot: **Alex has 90 coins.**

> **Someone's place**
>
> `{DBVAR_coins.rank[option_user]}`
>
> Bot: **4** (Alex is 4th).

The same idea works for built-in variables, like `{user_icon[{option_user}]}` or `{user_name[123456789012345678]}`. See [How to target someone else](/variables/built-in-variables#how-to-target-someone-else).

## 2. Put something in it: Save a value

Use it when you want to **put something new** in the box. Whatever was inside is replaced.

![The Save a value block and its settings](https://mintcdn.com/doge-bot/0C6-zgXTpDx1QOCe/images/guide/block-save-value.png?fit=max\&auto=format\&n=0C6-zgXTpDx1QOCe\&q=85\&s=8cf10bcdd7297d37ffcfede95376380e)

**1. Add the block**

Drag **Save a value** onto the canvas and join it with a line to the block above.

**2. Pick the variable**

Click the block. In **Custom Variable**, pick the variable to change.

**3. Whose variable? (User variables only)**

Pick **The member who started this** (the person who used the command), a **member input**, or a **user ID**. So `/give @Alex` can change Alex's box.

**4. Type the value**

In **Value**, type what to save. You can use other variables, like `{option_birthday}` or `{time_now_unix}`.

## 3. Add or take away: Do the maths

Use it for **numbers**: coins, XP, levels, counters.

![The Do the maths block and its settings](https://mintcdn.com/doge-bot/0C6-zgXTpDx1QOCe/images/guide/block-do-maths.png?fit=max\&auto=format\&n=0C6-zgXTpDx1QOCe\&q=85\&s=be60e5adbca755f937feb925cbbbe204)

Pick the variable and **Whose variable**, just like Save a value. Then, in **Equation**, the word `var` means *what's in the box right now*.

| Equation | What happens |
| - | - |
| `var + 50` | Adds 50 |
| `var - 10` | Takes away 10 |
| `var * 2` | Doubles it |
| `var / 2` | Halves it |
| `var + {option_amount}` | Adds what they typed |
| `var + {random[1,100]}` | Adds a random number from 1 to 100 |

**Rounding** decides how the answer is kept: a **Whole number** (7.6 becomes 8), **Keep some decimals**, or the **Exact answer**. Use Whole number so coins stay whole.

> [!NOTE]
>
> If the box is empty, Do the maths treats it as 0. So `var + 50` on a new member gives them 50.

### The Key box (for Objects)

Save a value and Do the maths both have an optional **Key** box. It shows for **Object** variables and for every **User** variable.

* **Key empty**: the block changes the **whole** value.
* **Key filled**, like `coins`: the block only changes that one part, like `profile.coins`.

See [Lists and objects](/variables/lists-objects-and-members).

## 4. Check what's inside: Compare

The **Compare** check (in the **Checks** tab) asks a question about two things.

* **Base Value**: `{DBVAR_coins}`
* **Comparison Type**: `Less Than`
* **Comparison Value**: `100`

If the person has less than 100 coins, the blocks joined **straight under** the check run. If not, the blocks under the **Else** block run. See [Checks and paths](/building-with-blocks/checks-and-paths).

## 5. Empty it: Clear a value

The **Clear a value** block empties a variable so it goes back to its starting value. For User variables, you can clear one person or **All Users** (to reset everyone, like a new season). The variable itself stays on the Database page.

> [!TIP]
>
> A value you change in a block is saved **at once**. Any block after it already sees the new value.

## Readable endings

Put a dot and a word after the name to show the value in a nicer way:

| Type this | You get |
| - | - |
| `{DBVAR_coins.formatted}` | `1,234,567` |
| `{DBVAR_coins.short}` | `1.2M` |
| `{DBVAR_coins.rank}` | This member's place, like `3` |
| `{DBVAR_coins.place}` | `3rd` |
| `{DBVAR_coins.leaderboard.10}` | A top 10 list (up to 25) |
| `{DBVAR_coins.top.1.member}` | Who is first |
| `{DBVAR_coins.top.1.value}` | How many the first person has |
| `{DBVAR_coins.total}` | Everyone's coins added up |
| `{DBVAR_coins.average}` | The average |
| `{DBVAR_coins.next.gap}` | How many more to pass the next person |
| `{DBVAR_coins.next.member}` | Who they need to pass |
| `{DBVAR_coins.rank[option_user]}` | Someone else's place |

The leaderboard endings only work on **User** variables.

> [!TIP]
>
> You don't have to remember these. On the **Database** page, press **Stored values** next to a variable. You'll see all the endings, a **Leaderboard maker**, and every member's value.

![The Stored values view with readable endings](https://mintcdn.com/doge-bot/0C6-zgXTpDx1QOCe/images/guide/ds-stored-values.png?fit=max\&auto=format\&n=0C6-zgXTpDx1QOCe\&q=85\&s=db9a81ed6bce8250339e59764e4ebf21)

## Full examples

**/balance**

A **Reply** block that shows your coins and your place:

```text theme={null}
{user_name}, you have {DBVAR_coins.formatted} coins.
You are {DBVAR_coins.place} in this server!
```

**/coin-flip**

**1. Slash command**

Make a slash command called `coin-flip`.

**2. Random chance**

Add a **Random chance** check set to 50%.

**3. Yes path**

**Do the maths** on `coins`, Whose variable: **The member who started this**, Equation `var + 10`. Then a **Reply**: `Heads! You won 10 coins. You now have {DBVAR_coins}.`

**4. Else path**

A **Reply**: `Tails! Better luck next time.`

## Common mistakes

| Problem | Why | Fix |
| - | - | - |
| The message shows `{DBVAR_coins}` as plain text. | The name is spelled wrong, or the variable does not exist. | Copy the chip from the Database page instead of typing. |
| The message shows nothing where the value should be. | The box is empty. | Give it a starting value, or add a backup like `{DBVAR_coins\|0}`. |
| Everyone shows the same coins. | The variable is not a **User** variable. | Make a **User** variable that stores a **Number**. See [Make a variable](/variables/make-your-own-variables). |
| The wrong person's coins change. | **Whose variable** is set to the wrong person. | Check Whose variable in Save a value and Do the maths. |

For a full system you can copy, see [Daily coins](/build-real-systems/daily-coins) and [A leaderboard](/build-real-systems/a-leaderboard).


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.