# Tutorial 3 — Scoring & Multiple Endings

Source: https://docs.skaz.io/tutorials/scoring-and-endings

> Tutorial: track a hidden score with variables and send each reader to the ending they earned with a Variable Router.

This is where branching gets powerful. Instead of each choice hard-wiring a
path, you'll track a hidden **score** that goes up when the reader is kind, and
at the end a **Variable Router** sends them to the ending they earned. Two
readers making different choices reach different endings — without you drawing
a separate branch for every combination.

**What you'll use:** an `int` [variable](/guide/variables),
[Change Variable Value](/guide/blocks#change-variable-value) blocks, and a
[Variable Router](/guide/blocks#variable-router) with
[conditions](/guide/choices#variable-router-conditions).

### Set up the story and the score

Create a story called *The Lost Puppy*. Open the **Variables** tab and create:

- **Name:** `kindness`
- **Type:** `int` (whole number)

It starts at `0` automatically, so you can add to it from the very first
choice — no need to initialize it.

### Write two scenes with choices

Add a starting **Text block**:

> You find a shivering puppy in the rain. Two kids are arguing over who found
> it first.

Give it two choices (in **Branching**):

- `Comfort the puppy first` → leads to a *kindness* step (next).
- `Ask the kids to settle down` → leads to a *neutral* step (next).

Add a second **Text block** for a later beat — *The puppy's owner appears,
frantic and grateful* — with two more choices:

- `Reunite them warmly` → another *kindness* step.
- `Hand it over and leave` → a *neutral* step.

Don't worry about wiring the endings yet — you'll do that last.

### Add kindness with Change Variable Value blocks

Between a kind choice and the block it leads to, drop a
**Change Variable Value** block:

- **variable_name:** `kindness`
- **delta:** `1`

These blocks are **instant** — the reader never sees them. They just bump the
score by 1 and move on. Point each *kind* choice at one of these blocks, and
have the block continue to the next scene. Leave the neutral choices going
straight through without a bump.

> To subtract instead, use a negative **delta** (e.g. `-1`) — handy for a
> "cruelty" or "suspicion" score.

### Route to an ending based on the score

After the last scene, add a **Variable Router** block:

- **routing_variable_name:** `kindness`

A router's branches aren't buttons — each is a *condition* (an operator and a
value), checked top to bottom, and the reader jumps to the first one that
matches. Add three branches in this order:

1. `> 1` → connect to a **Best ending** Text block (*The whole town hears how
   kind you were. The End.*)
2. `== 1` → connect to an **Okay ending** block (*You did right by the pup. The
   End.*)
3. **Otherwise** → connect to a **Neutral ending** block (*You went on your
   way. The End.*)

The last branch, **Otherwise**, always matches, so it's a **catch-all** for
everyone who didn't hit the ones above (including a score of `0`).

> Always end a router with an **Otherwise** branch. If no condition matches, the
> story has nowhere to go and gets stuck. Test every path in
> [preview](/guide/previewing) to be sure each score lands somewhere.

### Point the start block and preview

Make sure your first scene is the **starting block** (Set as start). Then open
the preview and play it a few ways:

- Make both kind choices → `kindness` reaches `2` → Best ending (`> 1`).
- Make one kind choice → `kindness` is `1` → Okay ending.
- Make no kind choices → `kindness` stays `0` → Neutral ending (**Otherwise**).

To double-check the score, temporarily add `Kindness so far: {{kindness}}` to a
scene's text — you'll see the number climb as you play. Remove it before
publishing.

## What you learned

- A hidden **`int` variable** can track a score across the whole story.
- **Change Variable Value** blocks adjust it invisibly, mid-branch.
- A **Variable Router** reads the score and picks an ending via **conditions**
  — with a **catch-all** so no reader is ever stranded.
- This scales: a handful of scoring choices produces many possible endings
  without drawing every path by hand.

## Where to go from here

You now know every building block Skaz offers. Combine them: score *several*
traits, gate a secret scene behind a `bool` flag with a
[Set Variable Value](/guide/blocks#set-variable-value) block, or personalize
endings with the reader's name from
[Tutorial 2](/tutorials/personalized-adventure). When it plays clean in
preview, [publish it](/guide/publishing) and watch the
[sessions roll in](/guide/tracking-plays).
