Chapter 8: Change
8.18. Random choices of things

As well as choosing random values, we often want to make a random choice of things or rooms. Perhaps a character is to wander about at random; perhaps a falling block of masonry will crush some random item. The value

random D
a random D

(the article "a" is optional) produces a random choice of the things in the world which fit the description D. For instance,

say "You can see [number of adjacent rooms] way[s] from here; how about [random adjacent room]?"

Unexpected results may follow if there is nothing in the game which fits the description, as then the random choice will be nothing. For instance, the above would then say:

You can see 0 ways from here; how about nothing?


132
* Example  Candy
One of several identical candies chosen at the start of play to be poisonous.

RB

Suppose we want to give the player a bag of candies, of which a random one is poisonous. We can pick which one should be poisoned at the start of play, like this:

"Candy"

The plural of piece of candy is pieces of candy. A piece of candy is a kind of thing. A piece of candy is always edible. Four pieces of candy are in the Halloween bag.

Toxicity is a kind of value. The toxicities are safe and poisonous. A piece of candy has a toxicity. A piece of candy is usually safe.

The Porch is a room. The player carries the Halloween bag.

After eating a poisonous piece of candy:
    say "Oh, that didn't taste right at all. Oh well!"

When play begins:
    now a random piece of candy is poisonous.

Test me with "eat candy / g / g / g".

133
* Example  Zork II
A "Carousel Room", as in Zork II, where moving in any direction from the room leads (at random) to one of the eight rooms nearby.

RB


PreviousContentsNext