| Chapter 18: Rulebooks |

| 18.7. New rulebooks

Creating a new rulebook is also straightforward, as we see in the following modest example game:

> "Appraisal"

> The Passage is east of the Tomb. The green-eyed idol is in the Tomb. A Speak-Your-Progress machine is in the Passage.

> Appraisal rules is a rulebook.

> An appraisal rule: say "Click... whirr... the score is [the score in words] points."

> An appraisal rule: if we have taken the idol then say "Most importantly of all, the idol has been found."

> Instead of switching on the machine, follow the appraisal rules.

The creation of the rulebook is all very well, but without the final sentence it would never be used. The crucial new phrase here is "follow ...", which is the first of several phrases allowing us to use rules whenever we want to (rather than simply at predetermined times such as when a particular action is being tried, or at the end of every turn, and such).

Like "number" or "text", "rule" and "rulebook" are kinds of value built into Inform: "the blossom rule" is a value whose kind is "rule", whereas "the every turn rules" is a value whose kind is "rulebook". In fact, Inform considers a rulebook to be a special case of a rule, so that whenever a rule is required it is legal to name a rulebook instead, but not vice versa. The "follow" phrase here...

> Instead of switching on the machine, follow the appraisal rules.

...expects to be applied to a value of kind "rule"; "the appraisal rules" is in fact a rulebook, but since that counts as a rule the phrase makes sense to Inform. To follow a rulebook means to run through all its rules in turn, stopping when one rule reaches an outcome; to follow a single rule means just that one, of course.

289
| Example In Fire or in Flood A BURN command; flammable objects which light other items in their vicinity and can burn for different periods of time; the possibility of having parts or contents of a flaming item which survive being burnt.

"In Fire or in Flood" Part I - Rules for combustion Heat is a kind of value. The heats are whole, damp, or flaming. A thing has a heat. A thing is usually whole. A thing has a number called endurance. The endurance of a thing is usually 5. A thing has a number called turns of burning. A thing can be flammable or flame-retardant. Before printing the name of something flaming: say "flaming "; Before burning something when the player is not carrying something flaming: if a flaming portable thing (called the lighter) is touchable begin; say "(with [the lighter], which you first take)[paragraph break]"; try taking the lighter; end if. Instead of burning something when the player is not carrying something flaming: say "You would first need a fire source." Instead of burning something flame-retardant: say "[The noun] is not the sort of thing that catches fire." Instead of burning something flammable when the player is carrying something flaming (called the flame source): say "You light [the noun] with [the flame source]."; change the heat of the noun to flaming. Instead of burning something when the player is in the noun: say "That seems dangerous given that you yourself are in [the noun]." Instead of burning something when the player is on the noun: say "That seems dangerous given that you yourself are on [the noun]." Instead of examining something: say "Hm, the [printed name] appears to be [heat]."; Before taking a flaming thing: let turns remaining be the endurance of the noun minus the turns of burning of the noun; if turns remaining is less than two, say "There's no portion of [the noun] sufficiently cool for you to pick up." instead. But that's only a small part of the battle. The thing about fire is that it keeps on doing fiery things even when the player is otherwise occupied: destroying items that are on fire, and spreading to other things nearby. So we need a set of rules for the fire's behavior. Every turn when something is flaming: follow the fire rules. The fire rules is a rulebook. A fire rule (this is the can't hold flaming objects rule): repeat with item running through flaming things begin; if the item is held by the player begin; let turns remaining be the endurance of the item minus the turns of burning of the item; if turns remaining is less than two begin; say "[The item] becomes too hot to hold! "; try dropping the item; if the item is held by the player, say "This is certainly painful."; end if; end if; end repeat. A fire rule (this is the flames spread rule): repeat with item running through flaming things begin; if the turns of burning of the item is one begin; spread the flames from the item; end if; end repeat. A fire rule (this is the fire destroys things rule): change started printing to 0; repeat with item running through flaming things begin; change the turns of burning of the item to the turns of burning of the item + 1; if the turns of burning of the item is greater than the endurance of the item, destroy the item; end repeat; if started printing is 1, say "[paragraph break]"; change started printing to 0. Because we've labelled all the fire rules, we could swap their order, or turn some of them off, while allowing the others run as usual. For instance, if there were a pair of fireproof gloves in the game, we might want to turn off the "can't hold flaming objects rule" whenever the player is wearing them. This sort of flexibility is especially useful in the context of extensions. Someone writing an extension about burning would have no way of anticipating the need for a Fireproof Gauntlet of Thog, but the author would nonetheless be able to implement one easily. Definition: a thing is vulnerable if it is flammable and it is whole. The contact between things is a critical factor when it comes to fire, so we might add a couple of conditional relations do determine what is touching what. Reliance relates a thing (called X) to a thing (called Y) when X is part of Y or X is in Y or X is on Y. The verb to be relying on implies the reliance relation. Contact relates a thing (called X) to a thing (called Y) when X is relying on Y or Y is relying on X. The verb to be joined to implies the contact relation. Having these at our disposal makes it much tidier to write what happens next: To spread the flames from (item - a thing): change started printing to 0; if the item is joined to a flammable whole thing (called the sacrifice) begin; if the sacrifice is visible begin; change started printing to 1; say "Flames engulf [the list of flammable whole things which are joined to the item]."; end if; now all the flammable whole things joined to the item are flaming; end if. Started printing is a number that varies. Started printing is 0. To destroy (item - a thing): let home be the holder of the item; if the item is part of something (called the superstructure), let home be the holder of the superstructure; if the item is visible begin; change started printing to 1; say "[The item] burns away[if something is relying on the item], leaving [a list of things which are relying on the item] behind[end if]. "; end if; if something is relying on the item, now all the things which are relying on the item are in the home; remove the item from play; now the item is damp; now every flaming thing which is part of the item is damp. To destroy (item - a door): let home be the holder of the item; if item is visible begin; change started printing to 1; say "[The item] burns away[if something flame-retardant is part of the item], leaving [a list of flame-retardant parts of the item] behind[end if]. "; end if; if home is a room, now all of the flame-retardant parts of the item are in the home; now the item is damp; change the item to open; change the item to unopenable. Before printing the name of a damp door: say "burnt-out frame of ". Instead of opening or closing a damp door: say "[The noun] can no longer be opened or closed in any meaningful sense." Instead of doing something other than examining or dropping to a flaming thing when the turns of burning of the noun is greater than 1: say "Fire has too thoroughly engulfed [the noun] for that to be a good idea." Instead of taking something when the noun is in a flaming thing (called the receptacle): say "You don't quite dare reach into [the receptacle]." Instead of touching something which is within a flaming thing (called the receptacle): say "It seems a little risky since [the receptacle] is on fire." Instead of turning something when the noun is contained in a flaming thing (called the receptacle): say "It seems a little risky since [the receptacle] is on fire." Instead of pushing or pulling something when the noun is inside a flaming thing (called the receptacle): say "[The receptacle] deters you." Before burning something which is in a container when the holder of the noun contains the player: say "This could make things toasty for you..." And that completes the rules which cover burning: things can catch fire, fire will spread, and gradually consume the world in flames. All of that was general and could be used in any setting, but we now provide a small game to show it off. Part II - Escape from the Library of the Dead The Library of the Dead is a room. "This room -- little, dank, stone -- is filling with some miasma you do not quite dare breathe. It is imperative that you get out." The desk is a flammable supporter in the Library. A drawer is part of the desk. The drawer is a flammable closed container. It is openable, lockable, and locked. The desk is scenery. A box is in the Library. A metal hinge is part of the box. The hinge is flame-retardant. The box is open, flammable, and openable. The shroud of Laertes is a flammable thing in the box. Instead of examining something when something is part of the noun: say "You note [the list of things which are part of the noun]." The world's last manuscript of the Psychagogoi by Aeschylus is on the desk. The manuscript is flammable. The manuscript has endurance 1. The torch is a flammable flaming thing carried by the player. It has endurance 60. The asbestos sack is a flame-retardant player's holdall in the drawer. The trapdoor is up of the Library and east of the Plaza. The trapdoor is a door. It is flammable, closed, lockable, and locked. "A trapdoor in the ceiling is your only hope of escape[if flaming]. Fortunately, it is rapidly burning through[end if]." The trapdoor has endurance 15. Instead of going through the closed trapdoor, say "[The trapdoor] is closed." We can then add a special fire rule to handle the trapdoor, which will be called as part of the same sequence. Again, this would be most important if the fire rules were part of a standard extension, and the trapdoor fire rule the author's own addition. A fire rule: if the trapdoor is flaming and a random chance of 1 in 3 succeeds begin; let the caught thing be a random flammable whole thing which can be touched by the trapdoor; if the caught thing is a thing begin; say "A spark from [the trapdoor] catches [the caught thing]!"; now the caught thing is flaming; end if; end if. Instead of going to the Plaza: say "Out at last!"; end the game in victory. Test me with "get manuscript / get shroud / light desk / look / g / open drawer / look / g / g / g / get sack / put shroud in sack / put manuscript in sack / close sack / light trapdoor / look / g / g / g / g / g / g / g / g / g / g / g / g / g / g / up".

Previous | Contents | Next