Choices and memory
Lives in: story/script.txt
Let the reader decide, and remember what they decided.
Open examples/example-02-choices-and-flags/story/script.txt while you read.
Flags
A flag is something the story remembers for the rest of the playthrough (and in saves).
[score = 0]
[helped = false]
[player_name = 'Hero']
Change later:
[score += 1]
[helped = true]
Print in dialogue:
HANA:
Score is {score}. Helped is {helped}.
Strings use single quotes inside the bracket: [some_text = 'hello'].
Choice menus
:: park
HANA:
What do you do?
> Help her. -> help_branch
> Stay back. -> skip_branch
:: help_branch
[helped = true]
HANA:
Thanks.
-> after
:: skip_branch
HANA:
Alright.
-> after
:: after
HANA:
helped is {helped}.
- Each
>line is one option. -> labelis where that option goes.- A bare
>with no arrow continues to the next moment in file order (NEXT).
Look and shuffle defaults live in game.json — Choice and character layout. Rich choice rules (show only if…, disable if…) need the direction file — Adding direction.
Branch on a flag
[if helped -> thank_you]
or, with more cases in data form, jump_if — same expression language. Use &&, ||, ! (not the words and / or).
[if score > 3 && helped -> good_ending]
Ask for a name
[input player_name "Your name?" default "Hero"]
The field starts empty with ghost text Hero. Enter with nothing typed stores Hero; or the reader types a name. On confirm the flag player_name is set. To start with real text the reader can edit, use prefill instead of default:
[input player_name "Your name?" prefill "Hero"]
Then:
HANA:
Nice to meet you, {player_name}.
More options (max_length, pattern, …): Reference when you need them. Look of the field: Choice and input looks.
Usually you need
| Want | Write |
|---|---|
| Remember | [flag = value] / += / -= |
| Show value | {flag} in text |
| Menu | > Caption. -> target |
| Gate a jump | [if expr -> target] |
| Name entry | [input flag "Prompt?"] |
Try this
- Add a third choice that does
[score += 2]. - Print
{score}after the branches meet. - Play twice and pick different options.
- After the branches meet, ask for a name with
[input]and use{player_name}in an ending.