Many older interactive fiction games required the player to find food and eat on a regular basis in order to avoid death. This effect was often unrealistic (since most people can survive much longer than a few hours without eating) and is often seen as an annoyance. However, for the sake of argument, suppose that we do want to construct a hunger-and-death system.
To make things a little more interesting, we will postulate that different foods are differently filling, so that if the player manages to find something really caloric, he is off the hook on his hunger search for a while.
We will also implement the system so that the player gets messages when he is hungry, then dies a short time later. (The times involved are ludicrously short, but this allows us to see the effects within a simple example. In a real game we would want to allow a considerably longer timer for the hunger to play out.)
First, a little scene-setting:
"MRE"
When play begins:
now the right hand status line is "[time of day]";
say "The procedure was painless at first: increased strength was the first sign, followed by a sensation of delayed time, as though everyone around you moved more slowly. Your ability to dodge and perform feats of agility doubled, then trebled. You were heralded as a triumph of medicine. They told you there would be no side effects worth speaking of.
They were wrong."
The Base Camp Larder is a room. "This room has been reinforced after each incident -- and there have been dozens in the last two months -- so that it now rivals Fort Knox. Only your new skill and speed enabled you to dodge the motion sensors, knock out the computerized security system, fool the retinal scanner, and punch a hole in the steel containment grating. But you're inside now."
Now we define our food, and add some special instructions for what happens to our hunger counters when the food is eaten:
Food is a kind of thing. Food is usually edible. Food has a time called the satisfaction period. The satisfaction period of a food is usually 5 minutes.
A person can be hungry or replete. The player is hungry.
The Larder contains an apple, a candy bar, and a large plate of pasta. The apple, the candy bar, and the pasta are food. The satisfaction period of the apple is 2 minutes. The satisfaction period of the pasta is 125 minutes.
Check eating something which is not food:
say "[The noun] might be edible, but it's not what you'd consider really food."
Check eating something when the player is not hungry:
say "You're not hungry right now."
Carry out eating something:
now the player is replete;
hunger resumes in the satisfaction period of the noun from now.
The first of those two phrases, "now the player is replete", causes the player to cease to be hungry; the second one sets up a future event in which the hunger sets in again. The length of time until that event depends on how satisfying the specific food is. Now we define that event:
At the time when hunger resumes:
starvation occurs in three minutes from now;
now the player is hungry.
At the time when starvation occurs:
if the player is hungry, end the story saying "You have starved".
Note "if the player is hungry": it is possible that the starvation event will be set up but the player will eat before it occurs; in that case, we want it not to take effect.
And now, since we really ought to give the player some warning of what is happening to him:
Every turn when the player is hungry:
choose a random row in the Table of Hunger Complaints;
say "[hunger entry][paragraph break]".
Table of Hunger Complaints
hunger
"Gosh, you're starving."
"It feels as though you haven't eaten in days. Weeks, almost."
"The world seems to slow down and everything becomes sharper and brighter. You are a hunter, a hunter of foodstuffs."
"You find yourself staring at [the random visible thing that is not the player] and wondering how it would taste."
Test me with "eat apple / z / z / z / eat candy bar / z / z / z / z / z / z / z / z / z".
First we define the events, and then we create a phrase to schedule them:
"Totality"
At the time when the penumbra appears:
say "The sunlight dies away to an eerie, brownish penumbra."
At the time when the eclipse begins:
say "The moon passes across the disc of the sun, plunging the world into darkness.";
now the Chamber is dark.
At the time when the eclipse ends:
say "The moon passes away from the sun, and a gloomy penumbral light returns.";
now the Chamber is lighted.
At the time when normal sunlight returns:
say "The sun shines once more bright in the sky, not to be eclipsed again on this spot for another thirty-seven years."
To schedule an eclipse for (totality - a time):
the penumbra appears at two minutes before totality;
the eclipse begins at totality;
the eclipse ends at three minutes after totality;
normal sunlight returns at five minutes after totality.
Now we make use of the new phrase:
When play begins, schedule an eclipse for 3:27 PM.
The Chamber is a room.
The time of day is 3:25 PM.
Test me with "z / z / z / z / z / z / z / z / z".
We shall see much more about creating phrases later. Their advantage is that they enable a complicated sequence of operations to be given a meaningful name, and that they can be re-used many times as needed.
Suppose we want to have a train which, at fixed times, arrives at and leaves stations. It should be possible for the player to get on and off the train when it is stopped, but not while the train is in motion.
"Empire"
The Empire Builder Train is a room. The Train has a room called the station. The station of the Train is Seattle.
The description of the Empire Builder is "One of the (relatively) plush long-distance Amtrak trains. You're in a two-story car with toilets and a cafe at one end, not having sprung for a sleeper.
[if the station of the Train is the train]Outside the window there is rapidly-passing countryside.[otherwise]Through the windows you can see the [station of the Train] train station.[end if]"
Instead of exiting when the player is in the Train:
if the station of the Train is the Train:
say "The train is not stopped at a station." instead;
otherwise:
move the player to the station of the train instead.
Before going outside when the player is in the Train:
try exiting instead.
Before going inside when the player is in the station of the Train:
move the player to the Train instead.
Seattle, Edmonds, Everett, Wenatchee, and Spokane are rooms. The description of a room is usually "The scenic train station of [the location][if the location is the station of the train].
The pompously-titled Empire Builder train is pulled up here, soon to continue its journey towards Chicago[end if]."
And now our schedule for the train -- somewhat truncated, admittedly, since the full three-day journey from Seattle to Chicago is a bit long even for an ambitious example.
At 4:45 PM:
if the player is in the train or the player is in the station of the train, say "The train pulls out of [the station of the Train]!";
now the station of the Train is the Train.
At 5:10 PM:
now the station of the Train is Edmonds;
if the player is in the train or the player is in the station of the train, say "The train pulls into Edmonds and comes to a stop."
At 5:17 PM:
if the player is in the train or the player is in the station of the train, say "The train pulls out of [the station of the Train], running north along the shore towards Everett.";
now the station of the Train is the Train.
At 5:39 PM:
now the station of the Train is Everett;
if the player is in the train or the player is in the station of the train, say "The train arrives in scenic Everett, WA: the last stop before it turns east and heads over the mountains."
At 5:44 PM:
if the player is in the train or the player is in the station of the train, say "The train pulls out of [the station of the Train] and turns east.";
now the station of the Train is the Train.
At 8:39 PM:
if the player is in the train or the player is in the station of the train, say "In darkness the train rolls into Wenatchee; which is just fine, considering that there is nothing to see here at all.";
now the station of the Train is Wenatchee.
At 8:44 PM:
if the player is in the train or the player is in the station of the train, say "The train pulls out of [the station of the Train] and continues east through the darkness towards Spokane.";
now the station of the Train is the Train.
Playing this out would of course require near inhuman patience. Let's set things up so that the player at least doesn't have to wait too long for his first departure:
The time of day is 4:43 PM.
...and provide fair warning of how slowly time is elapsing.
When play begins:
now the right hand status line is "[time of day]".
Test me with "out / in / z/ z / z / out / z / z / z / z / z / z / z / z / z / z / z / z / z / z / z / z / z / z / z / z / z / z / z / out / in / out / z / z".
Test more with "out / z/ z / z / z / z / z / z / z / z / z / z / z / z / z / z / z / z / z / z / z / z / z / z / z / z / z / z / z".
Here we allow the player to set the time at which some future event is going to happen, rather than letting the game decide. We'll need to borrow the syntax for defining new actions from a later chapter:
"Hour of the Wren"
When play begins:
say "You more or less stumble across them in Central Park: a disparate group of people, all of different ages, sitting in a circle. They aren't talking to one another -- in fact, they seem to be trying very hard to ignore one another, like people in the waiting room of an especially embarrassing kind of doctor. You are about to go around when a woman in a grey pressed suit comes up to you. Her suit-skirt is trimmed in lavender cord, and she looks as though she might have been extremely sharp-dressed in 1944. She hands you a card."
The Circle in the Grass is a room. "No one is looking at you, except for the secretary, if that is what she is."
The player carries a card. The description of the card is "Typed: 'Active astrology - dislike your fortunes? change your stars! - make an appointment now - hour of the wren STILL AVAILABLE.'".
The time of day is 1:55 PM.
Understand "pick [time]" or "choose [time]" or "make appointment for [time]" or "make an appointment for [time]" as making an appointment for. Making an appointment for is an action applying to one time.
Carry out making an appointment for:
say "Fate cannot be commanded more than once."
Instead of making an appointment for the time understood for the first time:
say "You settle on [the time understood] for your appointment. The woman makes a note of it in an appointment book, which she carries in a brown paper bag. 'Excellent choice, ma'am,' she says in a low, urgent voice. 'You'll be very satisfied.'";
stars shift at the time understood.
Understand "hour of the wren" as 2:00 PM.
At the time when stars shift:
end the story saying "insert cataclysm here".
Test me with "x card / make appointment for hour of the wren / z / z / z / z".