# Split a story across several Scripts

As a game grows, one Script per character turns into long files that repeat each other. `@script` runs another Script at that point in the conversation, then returns to the next line. You'll share the village's gossip between two characters, and split the elder's quest into a short Script for each stage.

## Before you begin

Complete [Build a merchant conversation](merchant.md) and [Build a quest giver](quest-giver.md). This guide edits the guard's, Odile's, and the elder's Scripts.

## Write a shared Script

Gossip is the same whoever tells it, so it belongs in one place. Create a Script named `Village Gossip` with a Label for each topic:

```dialogue
# wolves
The wolves came down from the hills when the snow melted early.
Nobody has seen a winter that short in forty years.

# elder
Maren has led Ashford since before the wall was built.
They say she has lost something precious, and won't say what.
```

These lines have no speaker, so they read as narration whichever character passes them on.

Then register the Script so other Scripts can call it. In the `Village` Compendium, open the **Scripts** section and add an entry:

| Field | Value |
| :--- | :--- |
| **Script** | `gossip` |
| **Script Asset** | `Village Gossip` |

## Run it from a conversation

Open the guard's `Gate Conversation`, which ends with his random remark, and add these lines at the end:

```dialogue
Guard: You'll hear plenty of talk in the village.
@script gossip
Guard: Make of that what you will.
```

When the conversation reaches `@script gossip`, it pauses, plays `Village Gossip` from its first line to its last, and then continues with *Make of that what you will.* The interface doesn't close in between, so the player sees one continuous conversation.

## Start at a Label

A character may only know part of the gossip. Add a Label identifier after the Script identifier to start there instead of at the top. Give Odile a choice in `Potion Stall`:

```dialogue
* What do people say about the elder?
  Merchant: Oh, you'll hear all sorts.
  @script gossip elder
  @go shop
```

Odile's version starts at `# elder` and skips the wolves entirely, then returns to her shop.

## End a topic with `@exit`

A Label marks where a Script can start, not where it stops. The guard starts at the top, so he tells the wolf gossip and carries on through `# elder` to the end of the file. To make each topic stand on its own, end it with `@exit`:

```dialogue hl_lines="4"
# wolves
The wolves came down from the hills when the snow melted early.
Nobody has seen a winter that short in forty years.
@exit

# elder
Maren has led Ashford since before the wall was built.
They say she has lost something precious, and won't say what.
```

Inside a Script that `@script` started, `@exit` ends only that Script, and the conversation returns to the caller. The guard now stops after the wolves and says *Make of that what you will.* To have him tell both topics, add `@script gossip elder` on the line below his first `@script`.

## Split a long conversation

The elder's `Lost Ring` Script is short now, but each stage tends to grow: more dialogue, more choices, more reactions. Move each stage into its own Script and keep the original as a router:

1. Create Scripts named `Ring Offer` and `Ring Reward`. Move the lines of the offer branch and the reward branch into them, and remove the indentation they had inside their branch, so each Script's first line starts at the left edge.
2. Register them in the `Village` Compendium as `ring-offer` and `ring-reward`.
3. Replace the branches in `Lost Ring` with calls:

```dialogue
@if ring-quest-done
  Elder: My ring hasn't left my finger since you brought it back. Thank you.

@or ring-quest-active
  @if has-ring
    @script ring-reward
  @else
    Elder: Any luck with my ring? I lost it somewhere near the old well.

@else
  @script ring-offer
```

The router reads like a summary of the quest, and a writer working on the reward opens a Script that contains nothing else.

## What a called Script shares

A called Script runs on the same **Dialogue** component as its caller, but it's still a separate file:

| Shared with the caller | Separate from the caller |
| :--- | :--- |
| The interface, which stays open. | Labels: `@go` only reaches Labels in its own Script. |
| **Source** and **Target**, so Commands act on the same characters. | The Local Compendium: each Script reads its own, plus the **Dialogue** component's and the global ones. |
| The visited-line memory and `@select` progress of the **Dialogue** component. | `@exit`, which ends only the Script it's written in. |

!!! warning "Keep shared definitions out of a Script's Local Compendium"
    An Actor or Command defined in the caller's Local Compendium isn't visible to the Script it calls. Put anything both need in a global Compendium, or on the **Dialogue** component.

If `@script` names an identifier that no Compendium defines, Dialogue logs `Unable to find script` in the Console and continues with the caller's next line.

## Verify the result

1. Talk to the guard. Confirm that both pieces of gossip play, then *Make of that what you will.*
2. Ask Odile about the elder. Confirm that she tells only the elder gossip and returns to her shop.
3. Run through the elder's quest again, as in [Build a quest giver](quest-giver.md), and confirm that every stage plays as before.

## Where to go next

- **[Compendiums](../../compendiums.md#scripts)** — register Scripts in a Compendium.
- **[Language syntax](../../syntax.md#script)** — the `@script` Command and its optional Label.
- **[Localization](../../localization.md)** — export each Script's lines for translation.
