| Chapter 7: Basic Actions |

| 7.3. Before rules

Despite what was said in the previous section, instead rules do not quite bypass all of the usual rules. Inform knows that certain actions require light: for instance,

> examining the napkin; looking; looking under the dining table

and if it is dark then none of these actions will be allowed, and any instead rules about them will not even be reached. Similarly, Inform knows that most actions require physical access to their objects: so "taking the napkin" would be blocked if the napkin were, say, inside a closed glass bottle, whereas "examining the napkin" would not. So an instead rule can only take effect if the action has already passed these basic reasonability tests.

"Before" rules genuinely precede checking of any kind. They also differ from instead rules in that they do not automatically stop the action in its tracks. Rather, they are provided as an opportunity to ensure that something else is done first. For example:

> Before taking the napkin, say "(first unfolding its delicate origami swan)".

whence

> >GET NAPKIN
> (first unfolding its delicate origami swan)
> Taken.

We have seen that instead rules automatically stop actions, whereas before rules automatically allow them to continue. We sometimes want to change this. The magic word "instead" can therefore be tacked on to any instruction in a before rule, and will have the effect of immediately stopping the action at that instruction. Thus the following two rules are (almost) equivalent:

> Before removing the key, instead say "It seems to be soldered to the keyhole."

> Instead of removing the key, say "It seems to be soldered to the keyhole."

Two special phrases can also be used: "stop the action" and "continue the action". Yet a third way to achieve the same effect, then, would be:

> Before removing the key: say "It seems to be soldered to the keyhole."; stop the action.

And to round off the discussion, these are also (almost) equivalent:

> Before taking the napkin, say "(first unfolding its delicate origami swan)".

> Instead of taking the napkin: say "(first unfolding its delicate origami swan)"; continue the action.

As a general principle, it is good style to use instead rules whenever blocking actions, and before rules only when it is genuinely necessary to do something first but then to continue: in fact, it is good style to use "stop the action" or "continue the action" as little as possible.

70
| Example Democratic Process Make PUT and INSERT commands automatically take objects if the player is not holding them.

"Stop" and "Continue" are most useful when we need to write rules that will have to stop the action some of the time but at other times let it pass; so for instance: "Democratic Process" Before inserting something which is not carried by the player into something: if the noun is in the second noun, say "Already done." instead; say "(first taking [the noun])[line break]"; silently try taking the noun; if the player is not holding the noun, stop the action. Before putting something which is not carried by the player on something: if the noun is on the second noun, say "Already done." instead; say "(first taking [the noun])[line break]"; silently try taking the noun; if the player is not holding the noun, stop the action. The Assembly Room is a room. "On most days, this room is used for elementary school assemblies; at the moment, it serves as a voting place." The ballot is on the desk. The desk is in the Assembly Room. The machine is a container in the Assembly Room. "On the ballot machine is a sign which reads 'PUT BALLOTS IN ME :)'." Understand "ballot machine" as the machine. Test me with "put ballot in machine".

71
| Example Sand Extend PUT and INSERT handling to cases where multiple objects are intended at once.

Previous | Contents | Next