# Variables

Source: https://docs.skaz.io/guide/variables

> Variables in Skaz: remember choices, keep score and branch on what the player did, with set, change and router blocks.

Variables are named values that your story remembers as the player plays
through it — they're the "memory" of your story, used to track state and
steer the player down different paths.

## Creating variables

Open the **Variables** tab in the right-hand panel. Click **+ Create
variable** to add a new one, then set its:

- **Name** — used to reference the variable from blocks.
- **Type** — one of:
  - `string` — text
  - `int` — whole numbers
  - `float` — decimal numbers
  - `bool` — true/false

Click the trash icon next to a variable to delete it.

## Starting values

You don't set a starting value when you create a variable — every variable
begins each playthrough at its type's default, so it's always safe to read or
change one even before you've explicitly set it:

| Type | Starts at |
|---|---|
| `int` | `0` |
| `float` | `0` |
| `bool` | `false` |
| `string` | `""` (empty text) |

So a `score` counter starts at `0` and you can add to it right away; a `bool`
flag like `has_key` starts `false` until something sets it `true`. If you want
a different starting value, put a [Set Variable Value](/guide/blocks#set-variable-value)
block right after your starting block to initialize it.

> Every player who starts your story gets their own private copy of these
> variables. They all begin at the defaults above and change independently as
> each person plays — one reader's choices never affect another's.

## Reading and writing variables

Variables are used by all of the [blocks](/guide/blocks):

| Block | What it does with variables |
|---|---|
| [Text](/guide/blocks#text) | Can display a variable's value inside its text — see below. |
| [User Input](/guide/blocks#user-input) | Saves the player's typed answer into a variable (`save_to`); can also display variables in its prompt/hint. |
| [Set Variable Value](/guide/blocks#set-variable-value) | Sets a variable to a fixed value. |
| [Change Variable Value](/guide/blocks#change-variable-value) | Adds/subtracts a number from an `int`/`float` variable. |
| [Variable Router](/guide/blocks#variable-router) | Branches the story based on a variable's current value. See [Variable Router conditions](/guide/choices#variable-router-conditions). |

## Displaying variables in text

To show a variable's current value to the player, wrap its name in double
curly braces: `{{variable_name}}`. You can use this inside a
[Text](/guide/blocks#text) block's text, or a
[User Input](/guide/blocks#user-input) block's prompt/hint.

For example, if a `string` variable named `name` holds `"Alex"`, the text:

```
Hello, {{name}}!
```

is shown to the player as:

```
Hello, Alex!
```

While editing, the placeholder is highlighted blue if the variable exists, or
red if it doesn't (likely a typo). If the variable doesn't exist at all when
the story is played, the placeholder is replaced with
`[variable name is not found]`.

## Example

A simple "trust" system:

1. Create an `int` variable named `trust`.
2. Whenever the player makes a kind choice, connect it to a
   [Change Variable Value](/guide/blocks#change-variable-value) block with
   `variable_name = trust` and `delta = 1`.
3. Later in the story, add a [Variable Router](/guide/blocks#variable-router)
   on `trust` with a `> 5` branch (friendly ending) and an **Otherwise** branch
   (neutral ending, catch-all) to send the player down a different path based on
   how they played.
4. Anywhere else in the story, write `Your trust level is {{trust}}.` to show
   the player their current score.
