§19.15. Two rulebooks used internally

Rulebooks handle almost all of the important tasks which an Inform work of IF must carry out in order to keep play going. We have seen them used in clarifying the player's command, supplying missing ingredients, processing the action to see what should happen, responding, and so on: by this point in the documentation, it must look as if Inform uses rulebooks for everything.

This is nearly true. There is not actually a super-rulebook controlling everything. (Such a super-rulebook would need to repeat itself and never finish, something a rulebook is not allowed to do.) Instead, what happens during play looks like so:

1. Following the "when play begins" rulebook.
2. Repeating:
    2(a). Reading and parsing a command into an action;
    2(b). Following the "action processing" rulebook;
    2(c). Following the "turn sequence" rulebook.
until the game has finished.
3. Following the "when play ends" rulebook.

The command parser occasionally calls on the services of activity rulebooks to help it, but otherwise gets on with its job in ways that we do not "see" as Inform 7 users. The rest of what happens involves rulebooks, and in particular two important beneath-the-surface rulebooks: action processing and the turn sequence.

The action processing rules are used whenever an action must be tried, by whoever tries it. This usually happens in response to player commands, but not always: it might happen because of a "try...", and it can certainly interrupt an existing action.

The turn sequence rules are used at the end of each turn, and include housekeeping as well as timekeeping. They consult the "every turn" rulebook, and advance the time of day, among other useful tasks.

In general, we should only modify the operation of these two crucial rulebooks as a last resort. Play can evidently fall to pieces if they cease to work normally.


arrow-up.pngStart of Chapter 19: Rulebooks
arrow-left.pngBack to §19.14. Abide by
arrow-right.pngOnward to §19.16. The Laws for Sorting Rulebooks

*ExampleTimeless
A set of actions which do not take any game time at all.

*ExampleElectrified
Adding a rule before the basic accessibility rule that will prevent the player from touching electrified objects under the wrong circumstances.

**ExampleEscape from the Seraglio
Replacing the usual response to TAKE ALL so that instead of output such as "grapes: Taken. orange: Taken.", Inform produces variable responses in place of "grapes:".

Here we move to a systematic way of giving different durations to different actions, including even variations on the same act -- so that for instance climbing a steep hill might take several minutes more than other going actions. We do this by setting a number, "work duration", to represent the number of minutes consumed by a given action, and then consulting a rulebook to find out how long the past turn's action should take. By default, an action will take 1 minute.

We'll start by emulating the behavior of "Uptempo": each turn we'll set the clock forward most of the way, then check to see what has changed since the last turn, print any relevant events, and only then set the clock forward the final minute. The exception is when an action is set to take no time at all; in that case, we'll skip the rest of the turn sequence rules entirely.

paste.png "Endurance"

Work duration is a number that varies.

Every turn:
    now work duration is 0;
    increment the turn count;
    follow the time allotment rules;
    if work duration is 0, rule succeeds;
    increase the time of day by (work duration minutes - 1 minute).

The time allotment rules are a rulebook.

A time allotment rule for examining or looking:
    now work duration is 0;
    rule succeeds.

A time allotment rule for going:
    now work duration is 2;
    rule succeeds.

A time allotment rule for going up:
    now work duration is 5;
    rule succeeds.

A time allotment rule for waiting:
    now work duration is 10;
    rule succeeds.

The last time allotment rule:
    now work duration is 1.

When play begins: now the right hand status line is "[time of day]".

The Quai is a room. "An attractive park at the edge of the river Aude: here you can wander among palm trees, and watch cyclists go by on the bike path; in the water there are ducks. In the cafe to your north, patrons sip their pastis; and above you is the medieval walled city and its castle."

The Cafe is north of the Quai. "A charming collection of umbrella-shaded tables, from which one can watch the river and the walls of the city beyond. The noise of traffic is only a minor distraction."

The City is above the Quai.

After going to the City:
    say "You struggle uphill for some distance...";
    continue the action.

At 9:15 AM:
    say "The bells ring out from Place Carnot."

Test me with "z / n / s / u".

**ExampleEndurance
Giving different actions a range of durations using a time allotment rulebook.

Here we move to a systematic way of giving different durations to different actions, including even variations on the same act -- so that for instance climbing a steep hill might take several minutes more than other going actions. We do this by setting a number, "work duration", to represent the number of minutes consumed by a given action, and then consulting a rulebook to find out how long the past turn's action should take. By default, an action will take 1 minute.

We'll start by emulating the behavior of "Uptempo": each turn we'll set the clock forward most of the way, then check to see what has changed since the last turn, print any relevant events, and only then set the clock forward the final minute. The exception is when an action is set to take no time at all; in that case, we'll skip the rest of the turn sequence rules entirely.

paste.png "Endurance"

Work duration is a number that varies.

Every turn:
    now work duration is 0;
    increment the turn count;
    follow the time allotment rules;
    if work duration is 0, rule succeeds;
    increase the time of day by (work duration minutes - 1 minute).

The time allotment rules are a rulebook.

A time allotment rule for examining or looking:
    now work duration is 0;
    rule succeeds.

A time allotment rule for going:
    now work duration is 2;
    rule succeeds.

A time allotment rule for going up:
    now work duration is 5;
    rule succeeds.

A time allotment rule for waiting:
    now work duration is 10;
    rule succeeds.

The last time allotment rule:
    now work duration is 1.

When play begins: now the right hand status line is "[time of day]".

The Quai is a room. "An attractive park at the edge of the river Aude: here you can wander among palm trees, and watch cyclists go by on the bike path; in the water there are ducks. In the cafe to your north, patrons sip their pastis; and above you is the medieval walled city and its castle."

The Cafe is north of the Quai. "A charming collection of umbrella-shaded tables, from which one can watch the river and the walls of the city beyond. The noise of traffic is only a minor distraction."

The City is above the Quai.

After going to the City:
    say "You struggle uphill for some distance...";
    continue the action.

At 9:15 AM:
    say "The bells ring out from Place Carnot."

Test me with "z / n / s / u".

Here we move to a systematic way of giving different durations to different actions, including even variations on the same act -- so that for instance climbing a steep hill might take several minutes more than other going actions. We do this by setting a number, "work duration", to represent the number of minutes consumed by a given action, and then consulting a rulebook to find out how long the past turn's action should take. By default, an action will take 1 minute.

We'll start by emulating the behavior of "Uptempo": each turn we'll set the clock forward most of the way, then check to see what has changed since the last turn, print any relevant events, and only then set the clock forward the final minute. The exception is when an action is set to take no time at all; in that case, we'll skip the rest of the turn sequence rules entirely.

paste.png "Endurance"

Work duration is a number that varies.

Every turn:
    now work duration is 0;
    increment the turn count;
    follow the time allotment rules;
    if work duration is 0, rule succeeds;
    increase the time of day by (work duration minutes - 1 minute).

The time allotment rules are a rulebook.

A time allotment rule for examining or looking:
    now work duration is 0;
    rule succeeds.

A time allotment rule for going:
    now work duration is 2;
    rule succeeds.

A time allotment rule for going up:
    now work duration is 5;
    rule succeeds.

A time allotment rule for waiting:
    now work duration is 10;
    rule succeeds.

The last time allotment rule:
    now work duration is 1.

When play begins: now the right hand status line is "[time of day]".

The Quai is a room. "An attractive park at the edge of the river Aude: here you can wander among palm trees, and watch cyclists go by on the bike path; in the water there are ducks. In the cafe to your north, patrons sip their pastis; and above you is the medieval walled city and its castle."

The Cafe is north of the Quai. "A charming collection of umbrella-shaded tables, from which one can watch the river and the walls of the city beyond. The noise of traffic is only a minor distraction."

The City is above the Quai.

After going to the City:
    say "You struggle uphill for some distance...";
    continue the action.

At 9:15 AM:
    say "The bells ring out from Place Carnot."

Test me with "z / n / s / u".