# Lock dialogue behind a requirement

RPG conversations react to what the player has done: a pass opens the gate, enough gold buys a favor, and a missing item closes a door. A **Condition** is a named set of checks that a Script reads with `@if`. You'll make the night guard let the player in with a pass, or for a bribe they can only offer when they can afford it.

## Before you begin

Complete [Run game actions from a conversation](run-game-actions.md). This guide reads the `has-gate-pass` and `gold` entries of the `Progress` Global Variable, and runs the `open-gate` Command from the guard's Local Compendium.

Create a new Script named `Night Gate` and assign it to the guard's **Dialogue** component.

## Define the Conditions

Open the `Village` Compendium, click **Add Condition…**, and create two Conditions:

| Condition | Checks |
| :--- | :--- |
| `has-pass` | A **Boolean** Condition whose value is the `has-gate-pass` entry of `Progress`. |
| `can-pay-toll` | A **Compare Numbers** Condition: the `gold` entry of `Progress`, **Greater Or Equal**, `20`. |

A Condition can hold several checks, and it's true only when all of them pass. These two need one check each.

## Branch on a Condition

`@if` followed by a Condition identifier runs the indented lines below it only when the Condition is true. `@else` catches every other case. Write the conversation in `Night Gate`:

```dialogue
Guard: The gate's closed after dark. Nobody gets in.

@if has-pass
  Player: I have a pass. Bram at the east gate gave it to me.
  Guard: That's his seal, all right. In you go.
  @run await open-gate

@else
  Player: Surely there's something we can work out.
  Guard: Come back in the morning.
```

Exactly one branch plays. A player with the pass gets through, and everyone else is turned away.

!!! warning "A missing Condition is always false"
    If no Compendium defines the identifier after `@if`, the check fails without an error, and the `@else` branch runs. When a branch never plays, check the spelling first.

## Lock a choice

A choice can carry its own Condition, written as `@if` and the identifier right after the asterisk. Replace the `@else` branch with two choices:

```dialogue hl_lines="9 10 11 12 13 14 15"
Guard: The gate's closed after dark. Nobody gets in.

@if has-pass
  Player: I have a pass. Bram at the east gate gave it to me.
  Guard: That's his seal, all right. In you go.
  @run await open-gate

@else
  * @if can-pay-toll Would 20 gold change your mind?
    Guard: It might. Quickly, before someone sees.
    @run await pay-toll
    @run await open-gate

  * I'll wait until morning.
    Guard: Wise choice. The wolves are out tonight.
```

The choices are indented under `@else`, so they only appear to a player without a pass. Add the `pay-toll` Command to the `Village` Compendium with a **Subtract Number** Instruction that removes `20` from the `gold` entry of `Progress`.

When `can-pay-toll` is false, the bribe stays in the list but the player can't pick it. Showing it tells the player that the option exists and what it takes. To remove unavailable choices from the list instead, turn on **Hide Unavailable** in the Script's **Settings** tab, or add `[hideUnavailable: 1]` to one choice in the group.

!!! info "A choice takes one Condition"
    The `@if` on a choice accepts a single identifier. To require several things, add more checks to that Condition in the Compendium.

## Check several things at once

Outside of choices, a line can test more than one Condition:

| Write | Runs its lines when |
| :--- | :--- |
| `@if has-pass can-pay-toll` | Both Conditions are true. |
| `@if has-pass` followed by `@or can-pay-toll` | The first is true, or else the second is. Only the first matching branch runs. |
| `@else` after either | No earlier branch in the chain ran. |

For example, a guard who lets in anyone with a pass or enough gold, and charges only those without a pass:

```dialogue
@if has-pass
  Guard: In you go.
@or can-pay-toll
  Guard: That'll be 20 gold.
  @run await pay-toll
@else
  Guard: No pass, no gold, no entry.
```

## Verify the result

Select `Progress` in the Project window and change its authored values between runs:

1. Set `has-gate-pass` off and `gold` to `10`, then talk to the guard. Confirm that the bribe appears but can't be picked, and that waiting until morning ends the conversation.
2. Set `gold` to `30`. Confirm that the bribe can be picked, the gate opens, and `gold` drops to `10` in Play mode.
3. Set `has-gate-pass` on. Confirm that the guard recognizes the pass and opens the gate without asking for money.

Return `has-gate-pass` and `gold` to their original values when you're done, because the next guides start from them.

## Where to go next

- **[Build a reusable skill check](example-1.md)** — pass a threshold to one Condition with metadata, instead of creating a Condition per value.
- **[Greet the player differently on each visit](remember-visits.md)** — branch on what the player has already heard.
- **[Compendiums](../../compendiums.md#conditions)** — how `@if`, `@or`, and `@else` chains are evaluated.
