wyOOtdocs

Worked examples

Using the reader's name

Ask once, refer back later.

On this page
Already know this?How it is built

Ask for a name once, then use it again. It takes almost no work, and it makes a story feel written for one person.

Try it#

Try it

The front desk

You are at the front desk of a small hotel. The clerk turns the guest book around and taps the first empty line. Name:

Fill in the answer above to continue.

  • name
Type any name. See where it comes back in the next scene and in the ending.

The map#

signgo upstairsask for room 1The front deskThe lobbyRoom 4The ground floor
The guest book asks for the name. The lobby uses it twice. Both endings use it too.

How it is built#

One text value#

You do not need to add this first. Creating a text field, below, adds a text value for the answer. Rename it to name in the field's Name (not shown to reader) setting.

The field#

In the first scene, at the end of the text, use Ask for text… and choose + Add a new text field…. In the settings that open:

  • Placeholder (grey hint in the box) is "Type your name".
  • Max length is 24.
  • Answer required is on, so the reader cannot continue with a blank name.

The scene has two choices, "Sign the book" and "Sign it with a flourish". Both continue to the same place, and either one saves the name. The text field is a side effect of continuing, so which one the reader picks does not matter.

Using it#

In the lobby, the clerk says the name twice. The text uses name from Insert a value… in two places, and both come out as whatever the reader typed.

The endings use it again. Room 4 has a card on the pillow with the name on it, and the clerk writes the name on a tag for room 1. The name is stored once and can be used as often as you like.

Why it works#

  • The name comes back at the moment it matters. The reader just typed it, and a few seconds later someone says it to them.
  • Using it in both endings means every path pays it off, not only one.
  • It is cheap. There is one field and four places where the text prints it.

Things to try#

  • Add a second field for a nickname or a pet's name, and use the two in different scenes.
  • Make the field optional and add a check that reacts if the name is empty. See Asking the reader for text.

Make your own copy#

Want to take it apart? Copy this story into your Studio and change it however you like.

Next#

For a taste of chance, read Rolling dice.