Suppose we have a cat which is supposed to react to (and destroy) the most interesting thing in its environment. There are several ways we could approach this problem, but for the sake of demonstration, let's have it follow a rulebook to figure out which thing it most wants to interact with. We will then return the chosen object as "the object produced by the cat behavior rules".
"Feline Behavior"
The Kitchen is a room. The cat is an animal in the Kitchen. In the Kitchen is a bowl, a ball of wool, a newspaper. The bowl contains a quantity of cream.
The cat is wearing a silver collar. The description of the cat is "It is wearing [a list of things worn by the cat]."
The player carries a closed openable container called a bag. The bag contains catnip.
The cat behavior rules is a rulebook producing an object.
A cat behavior rule when the cat can touch the catnip:
say "The cat frolics with the catnip until nothing remains of it.";
rule succeeds with result catnip.
A cat behavior rule when the cat can touch the cream:
say "The cat laps up the cream.";
rule succeeds with result cream.
A cat behavior rule when the cat can touch the ball of wool:
say "The cat makes the ball of wool into a useless tangle which must be discarded.";
rule succeeds with result ball.
A cat behavior rule when the cat can touch the newspaper:
say "The cat bats playfully at the newspaper until all the nasty boring articles are destroyed.";
rule succeeds with result newspaper.
A cat behavior rule:
say "The cat looks miffed at the lack of ready entertainment, and glares at you with yellow eyes as though wondering whether your pants leg is good for claw-sharpening.";
rule fails.
Every turn:
let the destroyed object be the object produced by the cat behavior rules;
if the destroyed object is not nothing:
now the destroyed object is nowhere;
say "[line break]Good thing you have no use for [the destroyed object] yourself.[paragraph break]".
Test me with "z / z / open bag / z / z".
We include the if rule succeeded... condition here because nothing will be returned if the cat's search failed (as for instance in the result of the final rule).
Naturally, if we wanted we could equally well ask "if rule failed...".
Suppose we'd like to have a dog which the player is allowed to name himself. We'd like to deal correctly with both
>name the dog fido
and
>name the dog "fido"
so we'll also need to strip quotation marks out of the command. We can do this as follows:
"Fido"
The Back Yard is a room.
A dog is an animal in Back Yard. The dog has some text called the nickname. The nickname of the dog is "nothing". Understand the nickname property as describing the dog.
Rule for printing the name of the dog when the nickname of the dog is not "nothing":
say "[nickname of the dog]"
Naming it with is an action applying to one thing and one topic. Understand "name [something] [text]" as naming it with. Check naming it with: say "You can't name that."
Instead of naming the dog with "nothing":
now the nickname of the dog is "nothing";
now the dog is improper-named;
say "You revoke your choice of dog-name."
Instead of naming the dog with something:
let N be "[the topic understood]";
replace the text "'" in N with "";
now the nickname of the dog is "[N]";
now the dog is proper-named;
say "The dog is now known as [nickname of the dog]."
Test me with "name the dog Fido / name the dog Lawrence / look / x lawrence / name Lawrence nothing / look / x lawrence".
Rules about concealment will affect "in the presence of", too. For instance, suppose we have a man with a pocket pet:
"Today Tomorrow"
The Temporary Employment Office is a room. "'Tomorrow's Temporary Workers - Today!' proclaims the logo over the door. The office is divided into two areas, the inner sanctum where you take calls and fiddle with the computer, and the outer area where workers take skill exams and watch inspirational videos ('Earn your way to partial benefits!', 'Vacation days and you!', 'Temping the Tomorrow Way', etc.)."
Maya is a woman in the Office. "Your coworker Maya sits at her own computer, diligently modifying all the [one of]pay rates in the database down from $9.00 an hour to $8.96[or]billing rates in the database up from $25.00 an hour to $25.04[purely at random]." She wears a trenchcoat. She carries a chihuahua. The description of Maya is "[if Maya is wearing the trenchcoat]She's wearing a trenchcoat, in a bizarre bid to keep your boss unaware of the chihuahua in her pocket. 'Because petsitters are really expensive!' she explained to you in an urgent hiss this morning over the coffeemaker. [otherwise]She looks cold. [end if]To all appearances, she is carrying [a list of unconcealed things carried by Maya]."
Maya's computer is scenery in the Employment Office. The description is "You can't see the screen from here, but she was perfectly happy to tell you what she was doing."
Rule for deciding the concealed possessions of someone (called carrier):
if the particular possession is the chihuahua and the carrier wears the trenchcoat, yes;
otherwise no.
Instead of eating something in the presence of the chihuahua:
say "[The chihuahua] yips at you! Maya looks despairingly at [the noun], which is obviously inciting it."
The desk is scenery in the Office. On the desk are a multi-line telephone and a printer. The description of the printer is "Every morning, this instrument of torture spits out a list of the assignments you have to fill - professional, attractive receptionist with level three Excel certification, at $7.05 an hour; that sort of thing. You spend the ensuing three hours trying to meet its tyrannical demands." The description of the multi-line telephone is "Line three blinks urgently at you. You'll pick it up again as soon as you can remember who it was you put on hold."
The player carries a double bacon cheeseburger and a chocolate shake. Understand "milkshake" or "beverage" as the shake. The description of the cheeseburger is "A minor self-indulgence to make up for the fact that you have to work through lunch." The cheeseburger is edible. The shake is edible. The description of the shake is "It has the consistency of spackle and is no longer cold, but there is some chocolatey goodness in it still." Understand "burger" or "hamburger" as the cheeseburger. Instead of drinking the chocolate shake: try eating the shake instead.
Test me with "x maya / x cheeseburger / drink shake / eat cheeseburger".
Unless we somehow get the trenchcoat away from Maya, the chihuahua will not be in view, and will not intervene in our lunch. All very well for the player character, but not so interesting to the story... To this end, we might add an unfortunate event, courtesy of later chapters:
The time of day is 11:45 AM.
At 11:47 AM: say "Your boss pokes his head in, temporarily free of the round of conference calls that occupy all his days. 'Maya,' he says. 'Your coat?' He shakes his head, clucking sadly. 'It doesn't say professional!' But mercifully Maya manages to take it off so slowly that he doesn't glimpse her pet before her phone rings again.";
now Maya carries the trenchcoat.