wyOOtdocs

Worked examples

Inventory

Pick up items, then use them.

On this page
Already know this?How it is built

Pick things up, carry them, and have the world respond to what you are holding. This is one list value and a handful of checks, and it produces a puzzle.

Try it#

Try it

The shed

You are in a cluttered shed. Three things hang on nails by the door: a coil of rope, a lantern and a small iron key. You are carrying coat.
  • bagcoat
Try picking up different items, in different orders, and climbing down with and without them. The panel shows the bag.

The map#

take thingsgo downback upneeds ropeclimb upjumplantern + keyno lanternThe shedThe cellarThe bottomThe chestEmpty handedA long fall
The shed loops back on itself while you collect. What you hold decides which routes down are open.

How it is built#

One list#

Add a value called bag and set its type to A list, of text. Give it one starting item, "coat". The coat does no work in the story. It is there so the line "You are carrying …" never prints an empty list.

Taking things#

Each pickup is a choice that loops back to the shed. "Take the rope" has two things attached.

  • The check does not contain "rope", so the choice disappears once you have it.
  • The effect Add an item, "rope", to the bag.

The lantern and the key work the same way.

Choices that need something#

In the cellar, "Climb down the rope" only shows if the bag contains "rope". Jumping is always available. That is a real choice, because jumping is a bad idea, and a reader with no rope has to decide whether to try it.

At the bottom, "Unlock the chest" needs two checks at once: the bag contains "lantern" and the bag contains "key". A reader holding only one of them sees neither "Unlock the chest" nor a way to get it, so they have to go back and fetch the other.

Text that changes with the bag#

The bottom's text has two show-only-if paragraphs. One appears if the bag contains "lantern" and describes the chest. The other appears if it does not, and says it is too dark to see. That is one scene doing the work of two.

Why it works#

  • The reader always has something to do. Even with an empty bag, one choice always shows: going back.
  • The puzzle is fair. The shed tells you about all three items before you decide what to take, and the cellar tells you there is a drop.
  • Different sets of pickups lead to different endings without any extra scenes. Three items give eight combinations, and the story only wrote three endings.

Things to try#

  • Add a fourth item that opens a shortcut.
  • Print the bag in the ending, so the text names everything the reader is carrying.
  • Add a choice that removes an item, such as using up the key. Use Remove an item.

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 talks to the reader by name, read Using the reader's name.