Worked examples
Rolling dice
A gamble with a seeded roll.
On this page
A gamble at a bridge. One roll decides whether the guard lets you pass, and a middling roll lets you try again. It is one number, one fork and a loop.
Try it#
The gate
- roll0
The map#
How it is built#
One number#
Add a number value called roll, starting at 0. It is only used to hold the result of the die.
A fork that rolls#
Add a fork titled "The roll". Open When readers arrive here… and add the effect Roll a number from … to …, from 1 to 6, on roll. Then add its rules.
- If roll is at least 5, send to "Waved through".
- If roll is at least 3, send to "So close".
- Otherwise, send to "Sent away".
The fork rolls first and checks second, so the rules see the new number. The reader clicked "Roll the die" and lands directly on the result.
Printing the number#
Each of the three result scenes says "The die lands on" and then the number, by inserting roll with Insert a value…. Because the number is fixed at the moment the reader arrives, each scene always shows the roll that led to it.
Rolling again#
"So close" has a choice, "Roll again", that leads back into the same fork. The fork rolls again and produces a new number, and the story goes on. Every trip through the fork uses up another roll from the reader's random sequence.
Why it works#
- Chance is confined to one place. Everything after the roll is an ordinary check, so every outcome is a scene you wrote.
- The middle band gives the gamble a texture. Three outcomes feel richer than a plain pass or fail, and "so close" makes the reader want to go again.
- Rolling again costs nothing except the risk. To make it costly, take a coin from the reader in the roll-again choice with Subtract, and hide it when they have none.
What the reader sees#
Each playthrough has its own random sequence. If a reader leaves halfway and comes back, they see the same rolls they had before. If they play the story again from the start, they get a different run.
In the box above, Restart and Replay from start both behave like a reader playing again, so each one gives you a fresh run of luck. In your own preview, restarting keeps the same rolls so you can reproduce a problem, and Reroll is the button that starts a new run.
Things to try#
- Change the thresholds and use the odds table in Randomness to see what happens to the chance of passing.
- Let the reader improve their odds. Add a number value called
bonus, have a "Offer him a coin" choice add 1 to it, and add a second effect on the fork, after the roll, that addsbonustoroll. See Math and comparing values. - Let a successful roll set a yes/no value, and check that value in a later scene.
Make your own copy#
Want to take it apart? Copy this story into your Studio and change it however you like.
Next#
For a story that changes on a second look, read A returning visitor.