Chapter 5: Text
5.6. Text with random alternatives

Sometimes we would like to provide a little quirky variation in text, especially in messages which will be seen often. We can achieve this with the "[one of]... [or] ... [or] ..." construction. In the text, "[one of]" must be followed by two or more alternatives divided by "[or]"s, and concluding with one of a variety of possible outcomes to say how to use the alternatives. The simplest is "[purely at random]":

"You flip the coin. [one of]Heads[or]Tails[purely at random]!"

Exactly half of the time the text will be printed as "You flip the coin. Heads!"; and the other half, "You flip the coin. Tails!".

Often, though, although we want a random choice, we would really prefer to avoid the same choice coming up twice running, because of the deadening effect of repeating the exact same message twice. So the "[at random]" option is provided to make a (uniformly) random choice of outcomes other than the most recent one.

"The light changes randomly again; now it's [one of]green[or]amber[or]red[at random]."

(Here we can safely say the light "changes", because the new colour cannot be the same as the one printed the last time.)

Randomness can also be used not to make the text constantly change, but to make it unique to this playing:

"The newspaper headline is: [one of]War Casualties[or]Terrorists[or]Banks[sticky random] [one of]Continue To Expand[or]Lose Out[sticky random]."

"Sticky randomness" means that a choice is made once only, and that it sticks from there on. Although the newspaper headline will change with each playing, it will not alter during play.

In the above techniques, the alternatives were all equally likely, but we can also have an idea of rarity:

"Zorro strides by, [one of]looking purposeful[or]grim-faced[or]deep in thought[or]suppressing a yawn[or]scratching his ribs[or]trying to conceal that he has cut himself shaving[as decreasingly likely outcomes]."

There are six outcomes here: the first is six times as likely as the last, and those in between are similarly scaled, so Zorro cuts himself shaving only once in 21 tries, while he looks purposeful almost a third of the time.

But suppose we want to tuck some useful information in these messages, and we want to be sure that the player will see it. Because all of the above options involve randomness, it's possible that an unlucky player might miss a clue placed into only one variant of the message. We can prevent this like so:

"You dip into the chapter on [one of]freshwater fish[or]hairless mammals[or]extinct birds[or]reptiles such as the black salamander[in random order]."

What happens is that a random order is chosen for the (in this case) four outcomes. If we print the above text four times, it will print each variation just once, and when one random cycle finishes, a new one begins. The effect is somewhat like the "shuffle album" feature on an iPod. (One small restriction: if there are more than 32 variations, purely random choices will be printed and there will be no guarantee that repeats are prevented.)

A simpler way to ensure that the player sees what we want is to remove the element of randomness altogether. For instance:

"[one of]The phone rings[or]The phone rings a second time[or]The phone rings again[stopping]."

"Stopping" here means that on the third and all subsequent printings, we stop at the last variation, that is, "The phone rings again." The alternative is "cycling", where we go back to the beginning:

"The pundits discuss [one of]the weather[or]world events[or]celebrity gossip[cycling]."

And round and round they go.


61
* Example  Radio Daze
A radio that produces a cycle of output using varying text.

RB
62
** Example  Camp Bethel
Creating characters who change their behavior from turn to turn, and a survey of other common uses for alternative texts.

RB


PreviousContentsNext