Inform 7 Home Page / Documentation

§19.9. Basis of a rulebook

Every rulebook works on a value supplied to it, though it doesn't always look that way. The kind of the value is called its "basis"; for example, if a rulebook works on a number, it's called a "number based rulebook". Most of the rulebooks seen up to now have been action based rulebooks:

Instead of eating the cake: ...

"Instead" is an action based rulebook, and the action it works on is the one currently being processed. Besides before, after and instead, other action based rulebooks include the check, carry out, and report rules; general rulebooks such as every turn rules, the visibility rules, the turn sequence rules; and rules specially for dealing with the actions of other characters, such as the persuasion and unsuccessful attempt rules. But we have also seen object based rulebooks:

Rule for reaching inside the flask: ...

"Reaching inside" is an object based rulebook, and here we're giving it a rule which applies if the object is the flask. Inform would reject something like:

Rule for reaching inside 100: ...

because 100 has the wrong kind to fit - it's a number, not an object. There are many object based rulebooks, because most activities built-in to Inform act on objects. For example, the "printing the name of" activity has three rulebooks attached to it: before printing the name of, for printing the name of, after printing the name of. All of these are object based rulebooks.

Finally, we've also seen scene based rulebooks (which is how rules like "when a recurring scene ends" worked, in the Scenes chapter).

If a rulebook is declared like so:

Marvellous reasoning is a rulebook.

then it is an action based rulebook. If we want something different, we must write something like this:

Grading is a number based rulebook.
Grading 5: say "It's five. What can I say?" instead.
Grading an odd number (called N): say "There's something odd about [N]." instead.
Grading a number (called N): say "Just [N]." instead.

When play begins:
repeat with N running from 1 to 10:
    say "Grading [N]: ";
    follow the grading rulebook for N.

which produces:

Grading 1: There's something odd about 1.
Grading 2: Just 2.
Grading 3: There's something odd about 3.
Grading 4: Just 4.
Grading 5: It's five. What can I say?
Grading 6: Just 6.
Grading 7: There's something odd about 7.
Grading 8: Just 8.
Grading 9: There's something odd about 9.
Grading 10: Just 10.

Here we needed a variation on "follow" which supplies the value to apply to:

follow (values based rule producing values) for (value)

This phrase causes the rule to be obeyed immediately (rather than simply at predetermined times such as when a particular action is being tried, or at the end of every turn, and such), and applies it to the value given, which must be of a matching kind. Example:

follow the reaching inside rulebook for the electrified cage;

And here is an example based on objects:

The flotation rules are an object based rulebook.
A flotation rule for the cork: rule succeeds.
A flotation rule for an inflated thing: rule succeeds.
A flotation rule: rule fails.

And we might use the flotation rules in a circumstance like this:

After inserting something into the well:
    follow the flotation rules for the noun;
    if the rule succeeded:
        say "[The noun] bobs on the surface.";
        now the noun is nowhere;
        say "[The noun] sinks out of sight."

arrow-up.png Start of Chapter 19: Rulebooks
arrow-left.png Back to §19.8. New rulebooks
arrow-right.png Onward to §19.10. Rulebook variables

Objects that can sink or float in a well, depending on their own properties and the state of the surrounding environment.