Memory: variables
Randomness
Dice rolls, chance and random picks, and how to test them.
On this page
Some moments need chance: a gamble, a lock that might give way, a stranger who might help. Wyoot supports randomness, with one rule that keeps stories understandable. Random effects only ever put a result into a remembered value. What the story does with that result is then an ordinary check.
There is no random jump that sends a reader to an arbitrary scene. You roll a number, then a fork or a check decides what the number means. That way every outcome is one you wrote.
The three random effects#
On a choice or an arrival, + Remember something offers these once your story has a value of the right type.
- Roll a number from … to … on a number value. Both ends are included, so 1 to 6 is a six-sided die.
- Set to yes some % of the time on a yes/no value. Enter a percent from 0 to 100.
- Pick a random item from a list on a text or number value. See Lists and inventory.
Each one uses up one draw from the random sequence, every time it runs.
Roll, and then decide#
The usual pattern is a fork that rolls and routes in one step. Add a fork and open When readers arrive here…. Add a roll of 1 to 6 into a number value called roll. Then write the fork's rules, top to bottom: if roll is at least 5, send to one scene, if it is at least 3, send to another, otherwise send to a third.
The gate
- roll0
The reader clicks "Roll the die" and lands on the result. They never see the fork. The scene they arrive at can print the number with Insert a value…, because a roll is just a value.
Odds#
With one six-sided die, "at least 5" happens one time in three, and "at least 3" two times in three. Write the thresholds to give the odds you want.
| Roll is at least | Chance of a d6 |
|---|---|
| 2 | 5 in 6 |
| 3 | 2 in 3 |
| 4 | 1 in 2 |
| 5 | 1 in 3 |
| 6 | 1 in 6 |
Rolling again#
The random sequence moves forward every time a roll runs. In the example, "Roll again" goes back into the same fork, and the fork rolls once more and gets a new number. That is why you can gamble repeatedly.
If you want a reader to roll once and live with it, roll in a scene they only pass through once, and never send them back into it.
Repeatable, on purpose#
Each playthrough gets its own random seed. From that seed, the same sequence of rolls always comes out the same. This has two useful effects.
- A reader who leaves halfway and comes back sees the same results they had, not new ones.
- When a reader plays the story again, they get a new seed and so a different run of luck.
Testing chance#
In Preview, the Reroll button starts over with a new seed. Press it several times to see the different outcomes, and confirm that every one of them leads somewhere sensible. Play each ending until you have seen all of them.
Design notes#
- Give a bad roll a story, not a stop. "The die lands on 2" followed by a chance to talk your way out is better than an instant loss.
- Make the odds readable. A reader should be able to guess roughly how risky a gamble is from the scene.
- Do not use chance for the important decisions in a story. Use choices for those, so readers feel responsible for how it ends.
Next#
Chance is one way to vary a story. The other is remembering what the reader has already done. Read Story history.