§9.11. Future events

We often want to arrange for something to happen at some point in the future. Here is yet another timepiece:

paste.png An egg-timer is in the Chamber. "A plastic egg timer in the shape of a chicken can be pressed to set it going."

Instead of pushing the egg-timer:
    say "It begins to mark time.";
    the egg-timer clucks in four turns from now.

At the time when the egg-timer clucks:
    say "Cluck! Cluck! Cluck! says the egg-timer."

The event here is called "the egg-timer clucks". It only happens if we instruct so, using one of the following phrases:

(rule) in (time) from now

This phrase causes the given rule to be run at a given time offset from the current time of day. Example:

the egg-timer clucks in 18 minutes from now;

(rule) in (number) turn/turns from now

This phrase causes the given rule to be run at a given number of turns after the current one. Example:

the egg-timer clucks in four turns from now;

(rule) at (time)

This phrase causes the given rule to be run at a given time of day. Example:

the egg-timer clucks at 11:35 AM;

If we know in advance what time we want something to happen, we can more simply write:

At 4 PM: say "The great bells of the clock tower chime four."

(Note that in either case such rules begin with the word "at": they are the only rules allowed to begin with the word "at".)

A small warning: timed events like these only have a chance to occur during the turn sequence, that is, once every turn. In most stories, one turn takes one minute, so there will in due course be a turn happening at exactly (say) 11:35 AM. But if the clock is being advanced faster than this, it's possible that there are turns at (say) 11:32 AM and then not until 11:37 AM. But an event set for 11:35 AM will nevertheless happen -- it will run at the first available turn after that time, which will be 11:37 AM. Events can thus happen up to half an hour late, though Inform cancels them if the elapsed time is greater than that.

The Scenes panel of the Index can be a useful way to see what events have been set.


arrow-up.pngStart of Chapter 9: Time
arrow-left.pngBack to §9.10. Calculating times
arrow-right.pngOnward to §9.12. Actions as conditions

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:

paste.png "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".

*ExampleMRE
Hunger that eventually kills the player, and foodstuffs that can delay the inevitable by different amounts of time.

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:

paste.png "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".

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:

paste.png "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".

**ExampleTotality
To schedule an eclipse of the sun, which involves a number of related events.

**ExampleEmpire
A train which follows a schedule, stopping at a number of different locations.

***ExampleHour of the Wren
Allowing the player to make an appointment, which is then kept.