> ## 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.

# Change a variable with blocks

> Save a value, Do the maths, and clearing values.

Showing a box is fun, but a box that never changes is boring. To **change** what is inside, you use blocks while your bot runs.

There are two blocks you will use all the time:

| Block | What it does | Example |
| - | - | - |
| **Save a value** | **Puts** a new value in the box. Whatever was inside is replaced. | Set `favourite_colour` to `blue`. |
| **Do the maths** | **Changes** a number with maths: add, take away, times, divide. | Add `100` to `coins`. |

You find both in the **Steps** tab of the block list. Or type their name into the block search.

## Save a value

Use it when you want to **put something new** in the box.

<Steps>
  <Step title="Add the block">
    Drag **Save a value** onto the board and connect it with a line.
  </Step>

  <Step title="Pick the variable">
    In the settings on the right, pick the variable to change, like `favourite_colour`.
  </Step>

  <Step title="Pick whose variable (User variables only)">
    If it is a **User** variable, **Whose variable** asks which member's box to change. Usually that is **the person who used the command**. You can also pick someone else, for example the member chosen in a User input, so `/give-role @Alex` changes Alex's box.
  </Step>

  <Step title="Type the new value">
    Type what goes in the box. You can use other variables here too, like `{user_name}`.
  </Step>
</Steps>

## Do the maths

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

<Steps>
  <Step title="Add the block">
    Drag **Do the maths** onto the board and connect it.
  </Step>

  <Step title="Pick the variable">
    Pick a Number variable (or a User variable that stores numbers), like `coins`.
  </Step>

  <Step title="Pick whose variable">
    Just like Save a value, pick which member's box to change.
  </Step>

  <Step title="Write the maths">
    Write what should happen. For example:

    * add 100 coins: `+ 100`
    * take away 50 coins: `- 50`
    * double the XP: `* 2`
    * halve it: `/ 2`

    You can use variables in the maths too, like adding the amount from a Number input.
  </Step>

  <Step title="Rounding">
    If your maths can make a number with a dot (like `12.5`), use **Rounding** to choose what happens to it, so coins stay whole numbers.
  </Step>
</Steps>

## The Key box (for Objects)

Both blocks have an optional **Key** box. It is for variables that hold an **Object** (a box with smaller boxes inside).

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

The Key box shows for every **User** variable, too.

## Object operation

When the variable is an **Object**, Save a value asks what you want to do:

| Choice | What it does |
| - | - |
| **Set a key** | Write a value into one small box. |
| **Get a key** | Read one small box and keep it for the rest of the run, for example as `{my_coins}`. |
| **Remove a key** | Throw away one small box and its value. |
| **Remove every key** | Empty the whole Object. |

The block on the board then says what it does, for example **Remove shop.coins**, so you can read your board at a glance.

## Clearing a value

To wipe a value back to empty, use the block that **deletes the value of a custom variable**. Type `delete` into the block search to find it. This only empties the value. The variable itself stays on the Database page.

## A tiny example: a /coin-flip that pays out

1. **Slash command** `/coin-flip`
2. **Random chance** (a Check) set to 50%
3. On the **yes** path: **Do the maths** on `coins`, `+ 10`, whose variable: the person who used it. Then **Reply**: `Heads! You won 10 coins. You now have {DBVAR_coins}.`
4. On the **else** path: **Reply**: `Tails! Better luck next time.`

<Check>
  A value you change in a block is saved **at once**. Any block after it already sees the new value.
</Check>


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