What would you like to learn about interactive stories?
Reader and Game Variables
Reader and game variables
Variables let an author personalize a story and remember what happens while a reader plays. Choose the kind by asking who changes the value and whether it belongs to the saved game:
| Kind | Typical values | How it changes |
|---|---|---|
| Reader variable | Name, pronouns, age, favorite color, or another reader preference | The reader saves it through Customize or an input inside a chapter |
| Game variable | Coins, health, inventory, a chosen route, or whether a key was found | The story sets a starting value and chapters change it during an active game |
The two kinds are separate. A story may have both a reader variable and a game variable named mood. Write {reader:mood} or {game:mood} to make the intended value clear.
See a simple example
Suppose an author creates a reader variable named name with the default value Alex. In chapter text, the author writes:
Welcome, {reader:name}!
A reader who chooses Sam sees “Welcome, Sam!” A reader who keeps the default sees “Welcome, Alex!”
The same story could have a Number game variable named coins. Writing {game:coins} shows the number of coins in the reader's current game.
Create and find variables
Create reader and game variables while editing the story:
- For reader variables, enable Readers can customize story variables, then choose Add Reader Variable.
- For game variables, enable Chapters can use game state, then choose Add Game State Variable.
- Enter the name, choose a type, set the default or initial value, and save the story.
Choose Manage Variables to open the Story variables page. Game variables first introduced by chapter conditions or changes are collected there too.
Create a variable before relying on it in chapter text. When editing a chapter, use Insert beside a listed variable to add the correctly spelled form without retyping it.
Choose a type
Both kinds use the same six types, but their allowed values can differ:
| Type | What it holds | Comparisons | Game-state changes | Can be compared with |
|---|---|---|---|---|
| Text | Any text | =, != |
Set, Remove | Text, Dropdown |
| Dropdown | Text with author-defined choices | =, != |
Set, Remove | Text, Dropdown |
| Number | Number (-100000 to 100000) | =, !=, <, <=, >, >= |
Increase, Decrease, Set, Set by formula, Remove | Number, Percent, Age |
| Percent | Number (0 to 100) | =, !=, <, <=, >, >= |
Increase, Decrease, Set, Set by formula, Remove | Number, Percent, Age |
| Age | Whole number (18 to 150) | =, !=, <, <=, >, >= |
Increase, Decrease, Set, Set by formula, Remove | Number, Percent, Age |
| Yes/No | Yes or No | =, != |
Set True, Set False, Reverse, Remove | Yes/No |
The add-variable type picker calls Text Free Text. After it is added, the Story variables page shows its type as Text.
Common choices include:
| Type | Reader-variable example | Game-variable example |
|---|---|---|
| Text | A name or description | The current location or a written clue |
| Dropdown | A pronoun set or favorite color | A chosen route from a fixed list |
| Number | A lucky number | Coins, damage, or points |
| Percent | A reader preference from 0 to 100 | Health, progress, or reputation |
| Age | A reader-selected adult age | A character age from 18 to 150 |
| Yes/No | Whether the reader wants an optional detail | Whether a key was found or a door is open |
Number, Percent, and Age can be compared with one another. Text and Dropdown can be compared with one another. Yes/No can only be compared with Yes/No.
When an author leaves a default or initial value untouched, Text starts empty, Number and Percent start at 0, Age starts at 18, and Yes/No starts at Yes. A Dropdown uses its first valid choice when it has no valid selected default.
Text and Dropdown values are inserted into the story as plain text. A saved value is not treated as chapter formatting or as another CHYOA tag.
Use clear, valid names
New variable names:
- may contain letters, numbers, and underscores;
- must begin with a letter or underscore;
- may contain no more than 100 characters.
For example, player_name is valid. The prefix is not part of the saved name. Include reader: or game: when using the name in chapter text; Insert does this for you.
The names if, elseif, else, endif, reader, game, true, and false are reserved and cannot be used for new variables.
Names cannot differ only by capitalization. Even so, names typed in chapter text are case-sensitive. Use the exact capitals shown on Story variables; {game:Coins} and {game:coins} are treated differently.
Open the focused instructions
Use Reader Variables and Customization for defaults, Customize, inline inputs, display order, editing definitions, and older reader syntax.
Use Game State Variables and Inventory for starting values, existing games, visibility, inventory ownership, change order, and maintaining definitions safely.
To print either kind inside prose, see Showing Reader and Game Values. To control access or change a game value when a chapter opens, see Chapter Conditions and Game-State Changes.
Before publishing
Check that:
- each value uses the appropriate reader or game scope;
- every variable has the intended type, default or initial value, and exact name;
- reader defaults and game starting values make sense before any choices are changed;
- chapter text uses
reader:andgame:prefixes consistently; - a reader sees plain text rather than unintended formatting from saved Text or Dropdown values.
2 comments
No comments yet
The story has no discussion yet. Leave a note here when a branch gives you something to say.
No chapter comments yet
No one has commented on this branch yet. Add the first note above.