| Chapter 18: Rulebooks |

| 18.8. Action- vs object-based-rulebooks

The example of the appraisal rules, earlier in the chapter, was a rulebook whose rules were not tied to any specific action or item. We simply created rules for this rulebook by writing "An appraisal rule: ..." But most Inform rules do apply to either actions ("Instead of drinking the wine: ...") or items ("Rule for reaching inside the flask: ..."); and these two sorts of rule belong to two sorts of rulebooks. For instance, the Before, Instead and After rulebooks are based on actions, while the rulebooks associated with activities (as used by rules like "Rule for printing the name of: ...") are based on items. (As it turns out, the appraisal rulebook was action-based: it simply happened that we never specified any requirements on the action.)

We have seen that the preamble for a rule can be quite complicated, but when we strip away the optional ways to limit its applicability, give it a name, and so forth, we are left with

> ...rulebook name... [about/for/of/on/rule] [...what to apply to...]

where the square-bracketed parts are optional. If the rulebook is object-based, the "...what to apply to..." should be a description, like "a container"; if action-based, it should be an action, like "examining an open door".

1. Action-based rulebooks. We have already mentioned before, after and instead. Other action-based rulebooks include the check, carry out, and report rules; general rulebooks such as every turn rules, the procedural 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. So the following would all be valid:

> An every turn rule on kissing Clark:
> say "Lois glares in your direction."

> Procedural rule about someone trying taking the hat:
> ignore the can't take people's possessions rule.

> Visibility rule for looking under something:
> if the player is carrying a lit thing (called lamp)
> begin;
> say "You shine [the lamp] under [the noun]...";
> there is sufficient light;
> end if;
> there is insufficient light.

...all of which will take place on the occasions when these rulebooks would ordinarily be used, but take effect only if the action is the one specified.

The persuasion rules are dependent on the current action, but, since they will only be consulted when we ask someone to do something, it is only useful to write rules like

> Persuasion rule for asking Kent to try going: ...
> Persuasion rule: ...

and not

> Persuasion rule for taking the blue egg-cup: ...

Theoretically, the when play begins and when play ends rules could be written as things such as "When play begins rule for looking: ...", but this is not useful in any way: actions are not happening then, so such rules would never take effect.

Because action-based rulebooks tend to be the more useful of the two types of rulebook under most circumstances, this is the kind of rule created by default if we say:

> The judgment rules are a rulebook.

Having done this, we would now be allowed to write

> A judgment rule for listening to the music:
> say "Oh, Mozart is really too tedious to endure."

> A judgment rule about Kent Taylor trying kissing the player:
> say "Well, he's no Clark Gable, let's put it that way."

> Judgment rule on eating Kraft dinner:
> say "Bright orange and in no way related to real cheeses."

2. Object-parametrized rulebooks. Each activity creates three of these. For instance:

> Rule for printing the name of ...something...

and equivalently, though less elegantly,

> Rule for printing the name ...something...
> Rule for printing the name for ...something...

Each activity also generates a before and after rulebook, as we've also seen. The reaching inside and reaching outside rules are also object-based rulebooks.

We may make new object-based rulebooks in the process of making new activities, of course, but sometimes a whole new activity is overkill, since an activity produces three rulebooks (before, for, after). We can instead create a simple rulebook so:

> The flotation rules are an object-based-rulebook.

Having done this, we would be allowed to write

> 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:
> consider the flotation rules for the noun;
> if the rule succeeded
> begin;
> say "[The noun] bobs on the surface.";
> otherwise;
> remove the noun from play;
> say "[The noun] sinks out of sight.";
> end if.

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

Here we want a rulebook to determine whether objects float or sink, so we create an object-based rulebook for the purpose. The more specific rules here, pertaining to corks and to inflated things, will be consulted first; then, as a default, the general flotation rule. We also want a switch that can turn flotation off at will. The rule about the big switch will be observed before the others because the when... clause makes it more specific than the other rules in the flotation rulebook. If we wanted, we could also put these rules into a rulebook in an explicit order, overriding Inform's automatic sorting by specificity. "Flotation" The Pumping House is a room. A well is a fixed in place container in the Pumping House. The description of the well is "[if something is in the well]On the surface of the water you can see [a list of things in the well][otherwise]There is nothing on the surface of the water, nor can you see into the depths[end if]." The well bottom is a container. The cork, the rubber ring and a lead ingot are in the Pumping House. A big switch is a fixed in place device in the Pumping House. "A big switch labelled 'MAKE EVERYTHING SINK' is mounted on one wall[if switched on]. It crackles with electricity[otherwise]. It is currently switched off and silent[end if]." A thing can be inflated or uninflated. A thing is usually uninflated. Before printing the name of an inflated thing: say "inflated ". The rubber ring is inflated. 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 when the big switch is switched on: rule fails. After inserting something into the well: consider the flotation rules for the noun; if the rule succeeded begin; say "[The noun] bobs on the surface."; otherwise; move the noun to the well bottom; say "[The noun] sinks out of sight."; end if. A thing can be sinking, rising, or static. A thing is usually static. Definition: a thing is wet: if it is in the well, yes; if it is in the well bottom, yes; no. Every turn: now every thing is static; repeat with item running through wet things begin; consider the flotation rules for the item; if the rule failed and the item is in the well, now the item is sinking; if the rule succeeded and the item is in the well bottom, now the item is rising; end repeat; now every rising thing is in the well; now every sinking thing is in the well bottom; if something is rising, say "[The list of rising things] rise[if the number of rising things is 1]s[end if] to the surface of the well."; if something is sinking, say "[The list of sinking things] sink[if the number of sinking things is 1]s[end if] out of sight." And finally a few description rules to make things look prettier: Rule for writing a paragraph about the well when the well contains something: say "The chief feature of the room is a concrete-sided well in which there float[if the number of things in the well is 1]s[end if] [a list of things in the well]." Rule for writing a paragraph about the well: say "The chief feature of the room is a concrete-sided well full of water." As we recall from the chapter on activities, "writing a paragraph about..." is an activity; activities are themselves structured as sets of object-based rulebooks. The activity "writing a paragraph about" uses three object-based rulebooks (before writing..., for writing..., after writing...). We could have made a flotation activity as well, but in general it is overkill to make an activity to make success/failure decisions. For that purpose an object-based rulebook is sufficient. Test me with "get all / put cork in well / put ring in well / put ingot in well / x well / get cork / get ring / switch switch on / put cork in well / put ring in well / x well / switch switch off / switch switch on".

Previous | Contents | Next