RB §7.1. Getting Acquainted

Talking about characters presents some special challenges. For one thing, some characters are referred to by a proper name, but others are not: so the story might want to talk about "Jack" but also about "the drunk pedestrian". In the absence of other information, Inform attempts to divine our intentions based on the words with which we defined a new character: but we can always override its guess with an explicit statement, such as

The Great Malefactor is proper-named.

Belfry demonstrates further how titles are set at the start of play.

The relation between the player and the other characters is not always static, however. Sometimes we want the player to learn a character's name part-way through play, and start referring to "the drunk pedestrian" as "Fernando". Similarly, the status of another character may change due to some twist of the plot. Gopher-wood ★★ shows how to change the name of a character mid-story, and Peers ★★ handles changing the character's rank.

Alternatively, of course, the player character may already know some of the other characters when the story begins, even if the player does not. In that case, we may want to add a tag-line or so of identification to a character's name when he first appears in the story. A Humble Wayside Flower ★★★ shows one way of doing this.

Another occasional challenge is dealing with such commands as EXAMINE DR. THISBY. The problem here is that Inform by default will understand the full stop after "Dr" to be the end of one command and the beginning of another, and will try to interpret "Thisby" as a verb. If we do have a story populated by such formally-addressed characters, we may turn to Punctuation Removal, which provides a phrase to remove the full stops in standard titles before attempting to interpret the command.

Other characters have physical characteristics as well as names, of course, and Meet Market demonstrates one way of implementing people with notable features.

Finally, in some IF, the roles of characters may change from playing to playing. If we are writing a replayable murder mystery, we might want to select a new culprit each time the story starts; for this, see Clueless.

See also

The Human Body for more on body parts and physical description
Memory and Knowledge for a way to refer to characters whom the player knows about but who aren't currently in the room

Examples

31. Belfry

paste.png "Belfry"

The Belfry is a room. A bat is in the Belfry. The bell is in the Belfry. Some woodworm are in the Belfry. A man called William Snelson is in the Belfry. A woman called the sexton's wife is in the Belfry. A man called a bellringer is in the Belfry.

In the Belfry is a man called the vicar. The indefinite article of the vicar is "your local".

Test me with "look".

135. Clueless

"When play begins" is the best point to initialize any aspects of the game that are meant to change between playings. For instance, in this scenario, we would randomly select one of the other characters to be guilty of murder:

paste.png "Clueless"

The murderer is a person that varies.

When play begins:
    now the murderer is a random person who is not the player.

The Billiards Room is a room. Colonel Mustard and Professor Plum are men in the Billiards Room. Miss Scarlet and Mrs White are women in the Billiards Room.

Instead of examining the murderer:
    say "[The noun] certainly looks fiendish!"

Test me with "x mustard / x plum / x scarlet / x white".

238. Meet Market

We have already seen that we can give things value properties -- a lamp has a brightness, for instance. Relations give us additional flexibility: since we may relate various things to various values, it is possible to describe a thing as having more than one value at the same time.

To demonstrate:

paste.png "Meet Market" by "K M and Eric Rossing"

Feature is a kind of value. The features are snub-nosed, gangly, comely, bright-eyed, and sulky.

Appearance relates various persons to various features. The verb to appear means the appearance relation.

Meet Market is a room.

Bob, Carol, Ted, and Alice are people in the Meet Market.

Bob appears snub-nosed and gangly.

Ted appears sulky and snub-nosed.

Carol appears comely and bright-eyed.

Alice appears bright-eyed and comely.

Yourself appears sulky and gangly.

Instead of looking:
    say "The snub-nosed ones: [list of people who appear snub-nosed][line break]";
    say "The gangly ones: [list of people who appear gangly][line break]";
    say "The comely ones: [list of people who appear comely][line break]";
    say "The bright-eyed ones: [list of people who appear bright-eyed][line break]";
    say "The sulky ones: [list of people who appear sulky][paragraph break]".

Test me with "look".

The same logic might be used to provide characters who have complex mood states: a person might be angry and sad, not merely one or the other -- feelings being what they are.

32. Gopher-wood ★★

Suppose that we want a character who starts out with a general epithet ("the bearded man") but is later introduced to the player properly ("Japheth"). In that case, we want to be able to tell Inform to stop using an article once the character has been given a proper name. We can do this like so:

paste.png "Gopher-wood"

The Ark is a room. A bearded man is in the Ark.

Instead of examining the bearded man for the first time:
    now the printed name of the bearded man is "Japheth";
    now the bearded man is proper-named;
    say "You peer at him a bit more closely and realize that it's Japheth."

Finally, we need to tell Inform to understand the man's name, but only when he's been introduced. For this purpose, we borrow from the chapter on Understanding:

Understand "Japheth" as the bearded man when the bearded man is proper-named.

Test me with "x japheth / x man / look / x japheth".

313. Peers ★★

Almost all of this example is the flummery of pomp and circumstance: only the first two paragraphs really do anything.

paste.png "Peers" by Elizabeth II R

A title is a kind of value. The titles are Baron, Viscount, Earl, Marquess, Duke and Prince.

A peer is a kind of man. A peer has a title. A peer is usually a Baron. Before printing the name of a peer, say "[title] ". Understand the title property as describing a peer.

The House of Lords is a room. Maltravers, Pollifax, Omnium and St Vincent are peers in the House of Lords. Omnium is a Duke. St Vincent is an Earl.

Ennobling is an action applying to one thing and one title.

Check ennobling:
    if the noun is the player, say "The Sovereign is the fountain of honour, and may not be ennobled." instead;
    if the noun is not a peer, say "Commoners should remain so." instead;
    if the title of the noun is the title understood, say "But that is his title already." instead;
    if the title of the noun is greater than the title understood, say "As he is already of the rank of [title of the noun], any such letters patent are liable to be deemed invalid, following the precedent of the Buckhurst Peerage Case (1876). Best not." instead.

Carry out ennobling:
    now the title of the noun is the title understood.

Report ennobling:
    say "'Whereas Our Parliament for arduous and urgent affairs concerning Us the state and defence of Our United Kingdom and the Church is now met at Our City of Westminster We strictly enjoining Command you upon the faith and allegiance by which you are bound to Us that the weightness of the said affairs and imminent perils considered (waiving all excuses) you be at the said day and place personally present with Us and with the said Prelates Great Men and Peers to treat and give your counsel upon the affairs aforesaid And this as you regard Us and Our honour and the safety and defence of the said Kingdom and Church and dispatch of the said affairs in nowise do you omit Witness Ourself at Westminster the Fifth day of November in the 43rd year of Our Reign,' you say, with unpunctuated serenity. The new [noun] bows stiffly."

Understand "dub [someone] a/an [title]" as ennobling.

Test me with "dub st vincent a baron / dub maltravers a marquess / look / examine marquess".

237. A Humble Wayside Flower ★★★

First we define the relationships we choose to acknowledge:

paste.png "A Humble Wayside Flower"

Marriage relates one person to another (called the spouse). The verb to be married to means the marriage relation.

Fatherhood relates one person (called father) to various people. The verb to engender means the fatherhood relation.

For brevity, we will ignore the existence of mothers. It is a sad world.

Siblinghood relates a person (called A) to a person (called B) when a person who engenders A engenders B. The verb to be sibling to means the siblinghood relation.

Family relates a person (called A) to a person (called B) when A is married to B or A engenders B or B engenders A or A is sibling to B. The verb to be related to means the family relation.

A person can be known or unknown. After printing the name of an unknown person (called the alien):
    if a known person (called the contact) is related to the alien:
        say " ([relation between alien and contact] of [the contact])";
        now the alien is known;
        rule succeeds.

To say relation between (first party - a person) and (second party - a person):
    if the first party is married to the second party:
        if the first party is female, say "wife";
        otherwise say "husband";
        rule succeeds;
    if the first party is sibling to the second party:
        if the first party is female, say "sister";
        otherwise say "brother";
        rule succeeds;
    if the first party engenders the second party:
        say "father";
        rule succeeds;
    if the second party is the father of the first party:
        if the first party is female, say "daughter";
        otherwise say "son";
        rule succeeds.

Pere Blanchard's Hut is a room. Percival Blakeney is a known man in the Hut. Marguerite is a woman in the Hut. Percival is married to Marguerite. Outside from the Hut is the Garden. Louise is a woman in the Garden. The Road to Paris is west of the Garden. Armand St Just is a man in the Road. Louise is married to Armand. Monsieur St Just is a man. He engenders Armand and Marguerite.

Test me with "out / west / east / west".

Monsieur St Just never appears on the scene in this piece, but if we did put him somewhere the player could find him, he, too, would be properly introduced.

RB §7.2. Liveliness

A character who sits still in a chair and does nothing is much less convincingly alive than one who seems to be pursuing some sort of personal agenda. There are all sorts of ways to achieve this, but the least challenging is by introducing some random change to descriptions, and by giving a character some very simple routine behavior to carry out.

For instance, we'll often want the characters in a room to be described doing different things every time we look at them. Camp Bethel ★★ shows how this may be done.

Every turn rules lend some sprightliness to otherwise-silent characters, as well:

Every turn when the player can see Mrs MacGillicuddy:
    say "Mrs. MacGillicuddy vacuums around [a random fixed in place thing which is in the location]."

We might expand on this by providing a whole table of things for Mrs MacG. to cycle through, or a text variation effect that gives her different activities every turn, as in

Every turn when the player can see Mrs MacGillicuddy:
    say "Mrs. MacGillicuddy [one of]vacuums around the furniture[or]tries to remove gum from the underside of the desks[or]causes a racket by testing the smoke alarm[or]makes a pointed comment or two about them as sit by idly while someone works her fingers to the bone[as decreasingly likely outcomes]."

This is no great innovation in characterization by itself, but it does at least remind the player that the character is alive and moving about, even when he isn't paying attention to her.

Annoyotron Jr demonstrates a character who actively tries to get our attention, and whose routine of behavior changes just slightly if we show signs of having reacted to him.

Lean and Hungry ★★★ implements a classic thief, a character who doesn't interact with the player much except to pick up valuable objects he finds left around the map. Later we will see rather more advanced ways to make characters act on their own goals and plans, but this kind of simple behavior is easily rigged as part of an every turn rule.

Finally, Text Foosball ★★★★ extends the every-turn-rule idea to create an opponent who joins us in a randomized game of table soccer.

With animal characters, this kind of repetitive, semi-random behavior is often adequate: we don't expect animals to talk, or pursue steady goals, or to take an interest in what we do in their presence (unless it involves a food they like to eat).

For people, we are likely to need an assortment of additional techniques.

See also

Animals for a domestic cat and dog

Examples

153. Annoyotron Jr

paste.png "Annoyotron Jr"

The Minivan is a room. The Open Road is outside from the Minivan. Pete is a man in the Minivan. "Pete [if the player has been in the Minivan for 3 turns]is starting to look bored[otherwise]is playing with his travel activity book[end if]."

Every turn:
    if the player has been in the Minivan for 5 turns, say "'Are we there [if saying no]now?'[otherwise]yet?' asks Pete.[end if]"

Instead of saying no:
    say "'Oh,' says Pete. There is a blessed, momentary silence."

Instead of going to the Open Road:
    say "You leap to your death.";
    end the story.

Test me with "z / z / look / g / g / g / no / z / z / z / no / z / out".

67. Camp Bethel ★★

paste.png "Camp Bethel"

Camp Bethel Kitchen is a room.

One use for text alternatives is to change the description of a room after first visiting. We've already seen, in the example "Slightly Wrong", how to do this with "[if visited] ... [otherwise] ... [end if]". But since the first description is printed once and the second description on all subsequent occasions, we could equally well write

The description of Camp Kitchen is "[one of]You've never been into the kitchen before, though you've spent many an hour in the dining lodge. The place is larger than you would have expected, and it has none of the fake rustic touches of the rest of the camp[or]A tidy, efficient industrial kitchen, without any of the kitsch rusticity found elsewhere[stopping]."

We might also want to liven up the behavior of people and animals, who are probably not doing the exact same thing every time we glance in their direction. There are more complex techniques for modeling the behavior of characters, as we will see in the chapters on Advanced Actions and Activities; but if we just want some textual variety, we might write something like:

Jeremy is a man in the Camp Bethel Kitchen. "Jeremy stands at his station, [one of]peeling white onions[or]briskly dicing onions[or]chopping celery[or]peeling carrots[or]tying fresh herbs together with string[or]putting all the vegetables into a large stock pot[or]watching over his boiling vegetable stock[cycling]."

And since (textual variation or not) we do want the player to be able to see all these objects:

Jeremy carries white onions, celery, carrots, and herbs. Jeremy's station is scenery in the kitchen. It is a supporter.

Jeremy is following a sequence of actions to do an implied task (still somewhat robotically, but it will do for now). Animals might be a bit more capricious, though:

Fluffy is an animal in the Camp Bethel Kitchen. "[one of]Fluffy is chasing its tail[or]Fluffy is staring out the window[or]Fluffy is rubbing itself against your leg[purely at random]."

A housefly is an animal in the Camp Bethel Kitchen. "A large housefly [one of]lands on a countertop[or]flies around noisily[or]circles Jeremy's chef hat[at random]."

The housefly's description is merely "at random" rather than "purely at random" because we want to show it doing a different thing each turn, whereas Fluffy could plausibly stare out the window for five turns in a row.

There are more complex ways to change and override the initial descriptions of people and things; if text alternatives do not get us far enough, we can turn to the "rule for writing a paragraph about," documented in the Activities chapter.

Another frequent use of text alternatives is to give characters a bit of variety in things they're likely to say many times in the course of a game:

Instead of telling Jeremy about something:
    say "Jeremy looks [one of]surprised[or]intrigued[or]nonplussed[at random]. '[one of]You don't say[or]That's very interesting[or]Do go on[or]I wish I'd known that sooner[at random]!'".

Or, with somewhat more complexity:

Instead of asking Jeremy about something:
    say "'[one of]Sorry,[or]I'm afraid[or]Hm,[at random] [one of]I don't know much about that[or]you've got me there[or]I haven't the faintest[at random],' Jeremy [one of]drawls[or]replies[or]comments[or]exclaims[at random]";
    say "[one of][or] huskily[or] throatily[or] silkily[or] in a deep manly voice[as decreasingly likely outcomes]."

Notice that, in that last line, our first option is entirely blank. If we put nothing as an element of the text alternatives list, this means that printing nothing at all is a viable alternative. In fact, we've made this the most common probability out of the decreasingly likely outcomes, so that five times in fifteen, or a third of the time the text is run, there will be no modifier printed at all.

Test me with "look / g / g / g / ask Jeremy about his feelings for me / ask jeremy about his amnesia / tell Jeremy about my unborn child".

As this example (alas) reveals, text alternatives will not go all the way toward making our characters into compelling conversationalists; we will have to wait until we know more about Actions. But at least we have abolished the default responses, and given Jeremy a touch of personality, however witless.

76. Lean and Hungry ★★★

paste.png "Lean and Hungry"

Substance is a kind of value. The substances are silver, gold, and lead. Everything has a substance. A thing is usually lead.

Definition: a thing is valuable if it is not lead.

The Limestone Cave is a room. "Not very big, and it doesn't go back far, but you'd hoped to find some shelter here. Outside it is raining exceptionally hard."

The sinister gentleman is a man in the Cave. "Leaning against the wall is a sinister gentleman in a threadbare waistcoat." The description is "He looks as though he might once have been quite well off."

After examining the gentleman:
    say "[The noun] smiles back at you in an unnerving fashion."

Now we make the rule that governs the gentleman's behavior. Here we're going to invoke the rules that allow characters besides the player to do actions. More about this can be found in the Advanced Actions chapter:

Every turn:
    if the sinister gentleman can touch something valuable (called the treasure) which is not carried by a person:
        try the gentleman taking the treasure.

Report the gentleman taking something:
        say "[The gentleman] slyly acquires [the noun] and tucks it into his pocket." instead.

That "not carried by a person" prevents the gentleman from stealing from the player (or, less plausibly, from himself). If we did want him to pick pockets, we could just have said "which is not carried by the gentleman".

The player is carrying a coin, a bust of Abraham Lincoln, a bottle of sherry, a small pistol, and a wad of Confederate cash. The coin is gold. The pistol is silver.

A locket is in the Cave. The locket is gold. "A broken gold locket lies on the ground, a token of your late Mama."

Test me with "get locket / i / drop locket / z / drop cash / z / x gentleman / drop all / z / z / look".

140. Text Foosball ★★★★

Suppose we want a game of foosball in which our opponent acts every turn, but does different things depending on where the ball currently lies. We can put together a sequence of every-turn rules to account for this, as follows:

paste.png "Text Foosball"

Use scoring.

The Lounge is a room. "The Lounge is appointed with everything necessary to rest and relaxation: a vending machine, a potted palm, a stack of Entertainment Weekly issues from 1993, and -- your pride and joy -- a foosball game."

The foosball game is scenery in the Lounge. Understand "table" or "football" or "foozball" or "fussball" or "soccer" as the foosball game. The game is a supporter. On the game is a small white ball. The ball can be still, approaching, receding, or unreachable. The description of the ball is "Currently [small white ball condition]."

After printing the name of the small white ball, say " ([small white ball condition])".

When play begins:
    now left hand status line is "You: [score]";
    now right hand status line is "Joey: [Joey's score]".

Some tiny men on sticks are part of the game. Understand "handles" as the tiny men. The description is "Okay, a couple of the tiny men have had their feet broken off, and the table surface itself is a bit warped, and the ball resembles a quail egg in respect of shape and color. This makes for a game of unusual randomness, but skill is overrated."

Instead of attacking or pulling or pushing the game when the ball is unreachable:
    say "You give the table a good shove, and the ball moves ever-so-slightly.";
    now the ball is still.

Instead of taking the white ball:
    say "You'd forfeit the game if you did that."

Instead of turning the tiny men when the ball is unreachable:
    say "The ball has somehow gotten to a mystical point on the table where it cannot be reached, no matter what. Close inspection reveals that this point has been marked in chalk with a tiny X. Not that that does any good."

Instead of turning the tiny men when the ball is approaching:
    if a random chance of 2 in 3 succeeds:
        if a random chance of 1 in 2 succeeds, now the ball is receding;
        otherwise now the ball is still;
        say "[if the ball is still]Thunk. [otherwise]Thwack! [end if]You keep the ball from reaching its goal! Now it is [small white ball condition].";
    otherwise:
        let Joey score.

To let Joey score:
    now the ball is still;
    now Joey's score is Joey's score + 1;
    say "The ball rolls neatly into your goal, despite your efforts. ";
    if Joey's score < score, say "You put the ball back in the center with a snap. No reason to worry yet; you're still ahead. Joey looks determined, though.";
    otherwise say "After allowing a moment or two for Joey's gloating to pass, you replace it at the center."

Instead of turning the tiny men when a random chance of 1 in 13 succeeds:
    if the ball is unreachable, continue the action;
    now the ball is unreachable;
    say "You hit the ball off-center and it rolls sluggishly into a little dip in the surface of the foosball table. ";
    if Joey's score > 7, say "'You did that on purpose!' Joey exclaims indignantly.";
    otherwise say "You and Joey exchange glances. This is never good."

Instead of turning the tiny men:
    say "You madly rotate the tiny men on sticks! ";
    if a random chance of 1 in 2 succeeds:
        say "Hoorah! You hit the ball!";
        now the ball is receding;
    otherwise:
        say "Somehow you fail to bring your monopodal player into contact with the ball."

Joey is a man in the Lounge. "Joey is hunkered over the foosball handles on his side of the table." Joey can be active or inactive.

Joey's score is a number that varies.

Every turn: now Joey is active.

Every turn when the ball is approaching and Joey is active:
    let total be Joey's score + score;
    if total > 9, make no decision;
    now Joey is inactive;
    let Joey score;
    rule succeeds.

Every turn when the ball is unreachable and Joey is active:
    let total be Joey's score + score;
    if total > 9, make no decision;
    now Joey is inactive;
    say "Joey glares angrily at the stuck ball."

Every turn when the ball is receding and Joey is active:
    let total be Joey's score + score;
    if total > 9, make no decision;
    if the ball is unreachable, make no decision;
    now Joey is inactive;
    if a random chance of 1 in 2 succeeds:
        if a random chance of 1 in 2 succeeds, now the ball is still;
        otherwise now the ball is approaching;
        say "Joey connects with your shot. Now the ball is [small white ball condition]!";
    otherwise:
        now the ball is still;
        say "Joey tries to block, but misses! Back it goes in the center, where it is [small white ball condition].";
        increment the score.

Every turn when the ball is still and Joey is active:
    let total be Joey's score + score;
    if total > 9, make no decision;
    if the ball is unreachable, make no decision;
    now Joey is inactive;
    if a random chance of 1 in 2 succeeds:
        now the ball is approaching;
        say "Joey hits the ball solidly down towards your goal. Now it is [small white ball condition].";
    otherwise:
        say "Joey fails to hit the ball in your direction. It remains [small white ball condition]."

Every turn:
    let total be Joey's score + score;
    if total > 9:
        if Joey's score > score, end the story saying "Rats! Joey wins!";
        if Joey's score < score, end the story finally saying "Victory is yours!";
        if Joey's score is score, end the story saying "A perfect tie."

RB §7.3. Reactive Characters

As we observe characters, so they observe us. Those who seem to have no awareness of what the player is doing often come across more like waxworks than like people. Zodiac demonstrates a scenario where the watchful presence of a dangerous criminal keeps the player from doing what he otherwise might, while Police State expands on this idea with a policeman who reacts to entire types of behavior in his presence, regardless of whether the culprit is the player or a third party. Noisemaking ★★★ has a crow who will fly away in response to any loud noises the player makes.

And, of course, we definitely want to have characters react to being looked at or otherwise interfered with. Search and Seizure ★★★ implements a smuggler who reacts when we try to confiscate his possessions. Pine 1 gives us a sleeping princess who can be woken by a variety of methods.

We wrap up this section with two complete puzzle scenarios that demonstrate what can be achieved by giving characters reactions to the player's behavior. A Day For Fresh Sushi ★★★★ has a fish who watches the player's actions and comments on them, while the live furnishings in Revenge of the Fussy Table ★★★★ instead comment every turn on the current state of the world, until the player has successfully sorted out all their complaints.

Examples

96. Zodiac

Notice that the following two scenarios do not have the same effect:

paste.png "Zodiac"

The Secluded Alley is a room. The Capricorn Killer is a man in the Secluded Alley.

The player carries a can of mace and a roll of duct tape.

Instead of doing something other than examining with the Capricorn Killer:
    say "You wouldn't dare!"

Test me with "x me / x killer / touch killer / smell mace".

...will prevent the player from doing anything else to the killer, but allow him free range of action with other objects. By contrast, the following will prevent him doing anything other than examining to any item:

paste.png "Zodiac"

The Secluded Alley is a room. The Capricorn Killer is a man in the Secluded Alley.

The player carries a can of mace and a roll of duct tape.

Instead of doing something other than examining something in the presence of the Capricorn Killer:
    say "You dare not attempt it!"

Test me with "x me / x killer / touch killer / smell mace".

But notice that because we specified "examining something", actions that take no object (like sing) are still not affected.

The most strict statement would be

paste.png "Zodiac"

The Secluded Alley is a room. The Capricorn Killer is a man in the Secluded Alley.

The player carries a can of mace and a roll of duct tape.

Instead of doing something other than looking or examining in the presence of the Capricorn Killer:
    say "You dare not attempt it!"

Test me with "x me / x killer / touch killer / smell mace".

Because we left "something" out, now the pattern does not have to match an activity with an object; it will match any activity at all. Singing too will be deemed too risky in the presence of our sinister foe. But we do need to make an exception for "look", or else we won't get even the room description.

154. Pine 1

Because scene rules are checked every turn, they can be useful for designing puzzles which have multiple solutions. Instead of deciding the puzzle is "solved" when the player does a certain action, we set up a scene that checks to see whether the player has achieved a certain outcome -- however he accomplished it.

For instance, in this scenario, we're waiting for Sleeping Beauty to wake up, and it doesn't much matter how...

paste.png "Pine"

A person can be asleep or awake. A person can be active or passive.

The Spinning Tower is a room. "A remote corner of the old castle, reserved for spinning and weaving tasks."

Sleeping Beauty is an asleep woman in the Spinning Tower. "[if asleep]Sleeping Beauty lies here, oblivious to your presence[otherwise]Sleeping Beauty stands beside you, looking a little confused[end if]." The description is "She is even more magnificent than the rumors suggested." Understand "woman" or "girl" or "princess" or "lady" as Sleeping Beauty.

Discovery is a scene. Discovery begins when play begins. Discovery ends when Sleeping Beauty is awake. Marriage Proposal is a scene. Marriage Proposal begins when Discovery ends.

When Discovery ends: say "Throughout the palace you can hear the other sounds of stirring and movement as the spell of centuries is broken."

Instead of waking an awake person: say "Redundant."

Instead of waking an asleep person: say "Yes, but how?"

Instead of attacking an asleep person:
    now the noun is awake;
    say "[The noun] sits bolt upright. 'Hey! Ow!' So much for that true love's kiss nonsense."

Instead of kissing an asleep person:
    now the noun is awake;
    say "[The noun] slowly stirs to wakefulness!"

Instead of throwing water at an asleep person:
    now the second noun is awake;
    now the noun is nowhere;
    say "You pour out [the noun] on [the second noun].

[The second noun] wakes, shuddering. 'Agh! I had a terrible dream about drowning and then-- Hey!'"

The player carries a jug of water. Understand "pour [something] on [something]" or "splash [something] at/on [something]" as throwing it at.

Test me with "x beauty / wake beauty / pour water on beauty".

187. Police State

paste.png "Police State"

Seventh Avenue is a room. "The bars are all closed now, and there aren't any good clubs to go to, so you're on your own for open-air entertainment."

Persuasion rule for asking the policeman to try doing something: persuasion fails.

Persuasion rule for asking someone to try doing something: persuasion succeeds.

Note that the policeman will never get to the second persuasion rule, so he will always refuse to do the player's nefarious bidding.

Charles, Thomas, and Larry are men in Seventh Avenue. Patricia is a woman in Seventh Avenue.

And here's an unnecessary aesthetic touch from a later chapter, which will round up the descriptions of your friends into a single paragraph:

Rule for writing a paragraph about someone who is not the policeman:
    let X be the number of visible people who are not the policeman;
    say "It's just [X in words] of you now: [a list of visible people who are not the policeman]. But it sure has been a rip-roaring evening."

The policeman is a man in Seventh Avenue. "A policeman with a very guarded expression is watching you."

Singing is an action applying to nothing. Understand "sing" as singing.

Report singing:
    say "A little the worse for wear, you sing."

Smelling a person is disorderly conduct. Tasting a person is disorderly conduct. Jumping is disorderly conduct. Singing is disorderly conduct.

Instead of someone trying disorderly conduct in the presence of the policeman:
    say "The policeman arrests [the person asked]!";
    now the person asked is nowhere;
    the rule succeeds.

Instead of disorderly conduct in the presence of the policeman:
    end the story saying "The policeman arrests you!"

Test me with "charles, look / charles, jump / look / policeman, sing / thomas, taste policeman / patricia, sing / look / jump".

Notice the difference between the two rules about disorderly conduct: the one for other people says 'the rule succeeds' to make sure that the action is counted as a success and not (as normally happens with instead rules) a failure. Most of the time we don't care whether actions are judged successes or failures, but it matters here, because if we type CHARLES, JUMP and the result fails, then text such as 'Charles is unable to.' will be printed - which would get in the way. So we declare the action a success.

38. Search and Seizure ★★★

Suppose we want a character who carries hidden objects, but only while he is wearing his jacket. If we deprive him of this, his other possessions become known. Furthermore, if we ever search him, his possessions also become known, and can thereafter be mentioned by us.

paste.png "Search and Seizure"

Size is a kind of value. The sizes are small, medium, and large. A thing has a size. A thing is usually small.

A thing can be licit or contraband. A thing is usually licit.

A thing can be discovered or secret. A thing is usually secret.

Now, we want the character to be able to hide small things if he has some sort of concealing garment on. We also want to be able to see anything that the player has already found once, perhaps by using the >SEARCH PERSON command. So:

Rule for deciding the concealed possessions of someone (called the suspect):
    if the particular possession is discovered, no;
    if the suspect wears something and the particular possession is small, yes;
    otherwise no.

The following rule, borrowed from a later chapter, assures that any items that are ever mentioned to the player will be treated as known from then on:

Before printing the name of something (called discovery): now the discovery is discovered.

The Customs House is a room. The smuggler is a man in the Customs House. The smuggler wears a leather jacket. He carries a bottle of Altairan rum, some raspberries, and a laser pistol. The pistol is large. The jacket is large. The rum and the raspberries are contraband. The description of the smuggler is "He has a bestubbled chin and a sinister eye."

The tourist is a woman in the customs house. The description is "The type who walks off home with a dozen contraband items in her pocket not because she means to steal things but because she's too stupid to understand that the law applies to herself." She wears a tight-fitting dress. The dress is large. The tourist carries a grapevine and an archaeological artifact. The grapevine is large and contraband. The artifact is contraband.

Report examining someone: say "[The noun] is [if the noun is wearing something]wearing [a list of unconcealed things worn by the noun] and [end if]carrying [a list of unconcealed things carried by the noun]."

Report examining someone who is concealing something contraband:
    say "[The noun] looks nervous. You can just tell."

Report examining someone who is carrying an unconcealed contraband thing:
    say "Your eye goes at once to [the list of unconcealed contraband things carried by the noun] which [the noun] is unable to hide";
    if an unconcealed licit thing is had by the noun, say ", though [if the noun is female]s[end if]he also has [a list of unconcealed licit things had by the noun]";
    say "." instead.

Notice that we can talk about what the smuggler wears, what he carries, and what he "has": things the smuggler has can be either worn or carried, so the phrase is useful if we don't care to make that distinction.

Instead of searching someone:
    say "[The noun] is revealed to be carrying [a list of things carried by the noun]."

Instead of confiscating the dress:
    say "You are not allowed to perform strip-searches in the public customs area."

Understand "confiscate [something]" as confiscating.

Confiscating is an action applying to one thing.

Check confiscating:
    unless the noun is had by someone who is not the player:
        say "You can only confiscate other people's possessions." instead.

Carry out confiscating:
    now the noun is carried by the player.

Report confiscating:
    say "Through the authority vested in you by the power of the Sovereign of Centauri Proxima, you make [the noun] your own."

Test me with "x smuggler / search smuggler / x smuggler / confiscate jacket / x smuggler / confiscate rum / confiscate pistol / x smuggler / confiscate raspberries / x smuggler".

Test more with "x tourist / confiscate dress / confiscate grapevine / x tourist / search tourist / confiscate artifact / x tourist".

196. Noisemaking ★★★

Suppose the current sequence of action handling is not quite enough for us: we'd also like to have a stage after reporting, where other characters can react to the player character's behavior after it has already happened and been reported on screen. Having such a stage is unlike using "after", because after occurs before reports and prevents them from being printed. So, for instance, we could allow the player to do any of a range of different actions that make loud noises, and have a nervous bird that reacts to all of them by flying away afterward.

To do this, we can add a new rule into the specific action-processing rules. (For a list of these, see the Rules index.) Moving rules around and adding new ones requires syntax that we will learn in the chapter on Rulebooks, but the present example is fairly straightforward:

paste.png "Noisemaking"

Section 1 - Procedure

The other-player response rule is listed after the report stage rule in the specific action-processing rules.

This is the other-player response rule:
    follow the observation rules.

The observation rules is a rulebook.

Section 2 - Scenario

Country Lane is a room. West of Country Lane is Outside the Farmhouse. East of Country Lane is Village Center. North of Country Lane is Open Field.

The player carries a drum.

The black crow is an animal in Country Lane.

Singing is an action applying to nothing. Understand "sing" as singing.

Report singing:
    say "You hum a little ditty."

Singing is a loud action.

Attacking the drum is a loud action.

The block attacking rule is not listed in any rulebook.

Report attacking something:
    say "THWACK!"

An observation rule for loud action in the presence of the black crow:
    let N be a random adjacent room;
    if N is a room, move the black crow to N;
    say "The crow, startled, flies off to [N]."

Test me with "sing / g / n / hit drum".

82. Revenge of the Fussy Table ★★★★

This example does include a number of features that we haven't met yet, particularly rulebooks. Nonetheless, the basic idea should be relatively clear. Our premise is that the player is faced with a series of disgruntled furnishings, none of which want to be responsible for supporting the cold, hot, drippy, or spiky objects lying around the room.

paste.png "Revenge of the Fussy Table"

Use scoring.

Section 1 - The Supporters

The Dining Room is a room. "A room of handsome proportions, with an octagonal dining table on a fine parquet floor. The original set of chairs has been taken away, leaving only a red velvet dining chair and a blue suede armchair."

The fussy table is a supporter in the Dining Room. It is scenery. The description is "It's hypochondriac: the result of a sojourn in a superior antique shop, where it picked up the scent of almond oil, words like provenance, and a secretive shame about being resurfaced.

Chairs don't get along with it.

In its mellowest moods, after a really good dusting, it will mention, casually, a cabinet it once knew, which was twelve feet tall, came from the Winter Palace, and had an asking price of $350K."

A chair is a kind of supporter with carrying capacity 1. A chair is enterable. A chair is usually scenery. Understand "chair" as a chair.

The blue suede armchair and the red velvet dining chair are chairs in the Dining Room. The description of the blue suede is "Quiet, mellow, and with a lingering aroma of clove cigarettes, and possibly something less legal. It doesn't sit up straight, and doesn't let anyone else do so either." The red velvet has the description "In temperament, in bearing, in everything it is the opposite of the blue suede chair. It is concerned for its duty all the time, has a rigidly straight back, and pokes diners in the spine when it suspects them of overdoing things."

The carrying capacity of the player is 2.

Section 2 - Sources of Unpleasantness

A thing can be drippy or dry.

Heat is a kind of value. The heats are luke-warm, cold, and scalding. Everything has a heat. Understand the heat property as describing a thing.

A thing can be spiky or smooth. The cleated left shoe is a wearable spiky thing. It is worn by the player. The cleated right shoe is a wearable spiky thing. It is worn.

Definition: a thing is unpleasant if it is scalding or it is cold or it is spiky or it is drippy.

Definition: a supporter is occupied if something is on it.

Definition: something is contented if it is not concerned.

Definition: a chair is concerned if something unpleasant is on it.

Definition: the table is concerned if something drippy is on it or something scalding is on it or something spiky is on it.

Definition: the ceramic tile is concerned if something spiky is on it.

Definition: a room is concerned if something drippy is in it or something scalding is in it or something spiky is in it or someone which is in it is wearing a spiky thing.

Before printing the name of a drippy thing: say "drippy ". Before printing the name of a cold thing: say "cold ". Before printing the name of a scalding thing: say "scalding ".

Section 3 - What the Player Can Do About It

After putting a cold thing on a scalding thing:
    say "[The noun] meets [the second noun]; both shriek in pain. But the necessary heat transfer occurs.";
    now the heat of the noun is luke-warm;
    now the heat of the second noun is luke-warm.

After putting a scalding thing on a cold thing:
    say "[The noun] meets [the second noun]; both shriek in pain. But the necessary heat transfer occurs.";
    now the heat of the noun is luke-warm;
    now the heat of the second noun is luke-warm.

After taking a scalding thing:
    say "'Right,' you say. 'I'll just hold onto [the noun], shall I? Because that won't be in the least uncomfortable for me.'"

After taking a drippy thing:
    say "With a sense of martyrdom, you retrieve [the noun], which dribbles water down your cuffs."

After entering a chair when the player is wearing a spiky thing (called the clog):
    say "You sit on [the noun], lifting [the list of spiky things worn by the player] so that the parquet is no longer affronted."

Section 4 - In Which the Furnishings Complain

An every turn rule:
    follow the complaint rules.

The complaint rules is a rulebook.

A complaint rule:
    if something (called the offending item) on the table is drippy:
        say "'Help! Get me a coaster!' screams the table[if the table is visible], its veneer squirming under [the offending item][otherwise] from the Dining Room[end if].";
        rule succeeds;
    if something (called the offending item) on the red chair is drippy:
        say "'Oh dear,' murmurs the red chair, as [the offending item] drips into its velvety seat. 'Oh dear, I will have a damp spot. This is so very -- what will people think?'";
        rule succeeds;
    if something (called the offending item) on the visible armchair is drippy:
        say "[The offending item] visibly begins degrading the suede where it sits. The armchair is tactfully silent.";
        rule succeeds;
    if a drippy thing (called the offending item) is in the location and the player is in the Dining Room:
        say "'Cripes,' says the parquet. 'No one mind me at all. Just leave that [offending item] right here. You know I'm the most valuable thing in the room?'";
        rule succeeds.

A complaint rule:
    if a cold dry thing (called the offending item) is on the table:
        say "The table shivers under [the offending item].";
        rule succeeds.

A complaint rule:
    if something (called the offending item) on the table is scalding:
        say "'Hey!' protests the table, practically smoking at [the offending item]. 'Heard of a trivet?'";
        rule succeeds;
    if something (called the offending item) on the armchair is scalding:
        say "The armchair doesn't complain about [the offending item]; it just begins, quietly, to give off warm sweet clouds of blue steam, as though its inner opium-nature had been released.";
        rule succeeds;
    if something (called the offending item) in the Dining Room is scalding:
        say "'Yes indeed,' [if the location is the Dining Room]says[otherwise]bellows[end if] the parquet. 'That [offending item] won't leave any sort of mark what-so-ever.'";
        rule succeeds.

A complaint rule:
    if something (called the offending item) on the table is spiky:
        say "The table holds very very very still lest [the offending item] mar its finish. But its resentment is palpable.";
        rule succeeds;
    if something (called the offending item) on the velvet chair is spiky:
        say "[The offending item] stabs the velvet of the red velvet chair, which draws itself up even more sharply in a pose of dutiful martyrdom.";
        rule succeeds;
    if something (called the offending item) which is spiky is on the ceramic tile:
        say "'[The offending item] itches!' cries the ceramic tile.";
        rule succeeds;
    if something (called the offending item) in the location is spiky:
        say "'[The offending item] should not be on a parquet floor,' sings the parquet floor sadly.";
        rule succeeds;
    if someone (called the offending person) in the location is wearing something spiky and the location is the Dining Room:
        say "The parquet floor mutters about the things people wear to walk on parquet floors these days.";
        rule succeeds.

A complaint rule:
    if the table supports something which supports a drippy thing (called the offending item),
        say "'[The offending item] could still theoretically dribble down here,' says the table nonchalantly. 'It's possible.'";
    if the velvet chair supports a concerned thing (called the friend),
        say "'[The friend] seems a little worried,' remarks the velvet chair helpfully."

A complaint rule:
    if the concerned table can see a supporter (called the object of envy) which is not concerned:
        say "The table looks jealously at [the object of envy]. 'Some people have such an easy life.'";
        rule succeeds.

Instead of going to an adjacent room when the player is in the Dining Room:
    say "'You're not leaving!?' whimpers the table at once."

Moreover, every time the player gets close to resolving this issue, his unhelpful companion Alison brings in something else inconvenient. We can use the counting of contented supporters to decide when the player is getting close to winning and it's time for her to bring something else...

Section 5 - Source of Further Complications

The Tidy Kitchen is south of the Dining Room. Alison is a woman in the Tidy Kitchen. The kettle is a scalding thing. The ceramic tile is a cold portable supporter. It has carrying capacity 1. The platter is a scalding portable supporter. It has carrying capacity 1. The glass of ice water is a cold, drippy thing.

Instead of drinking the glass of ice water, say "It's not yours, it's for Alison, once she finishes cooking."

Alison carries the kettle, the tile, the platter, and the glass.

An every turn rule:
    follow the behavior rules.

The behavior rules is a rulebook.

A behavior rule:
    if ice water is carried by Alison and the player is in the Dining Room and almost all of the supporters are not concerned:
        let the next victim be a random fixed in place contented supporter;
        move the ice water to the next victim;
        say "Humming to herself, Alison brings in [an ice water] and sets it down smack on [the next victim], then goes back out.";
        rule succeeds.

A behavior rule:
    if platter is carried by Alison and the player is in the Dining Room and almost all of the supporters are not concerned:
        let the next victim be the red velvet chair;
        move the platter to the next victim;
        say "Whistling a jaunty tune, Alison brings in a hot platter and deposits it on [the next victim], then returns to the kitchen.";
        rule succeeds.

A behavior rule:
    if the tile is carried by Alison and the player is in the Dining Room and almost all of the supporters are not concerned:
        let the next victim be a random contented chair;
        move the tile to the next victim;
        say "Humming to herself, Alison brings in [the tile] and sets it down smack on [the next victim], then goes back out.";
        rule succeeds.

A behavior rule:
    if kettle is carried by Alison and the player is in the Dining Room and at least three fixed in place supporters are contented:
        let the next victim be the fussy table;
        move the kettle to the next victim;
        say "Just then the kettle boils in the kitchen. Whistling chirpily, Alison brings it in and sets it down smack on [the next victim], then goes back out.";
        rule succeeds.

And just so that the player knows where he stands at the end of each turn:

Section 6 - General Assessment

An every turn rule:
    if some of the things are concerned, say "You sense some resentment from [the list of concerned things]."

An every turn rule:
    if the player is carrying more than one scalding thing:
        let the dropped item be a random scalding thing carried by the player;
        say "You can't hang onto so many burning hot things, and lose your grip on [the dropped item].[line break]";
        silently try dropping the dropped item.

An every turn rule:
    if almost all of the supporters are concerned,
        say "'I hope everything is going well,' bellows Alison from the other room."

Finally, we need some rules to decide when the player is, in fact, finished.

Section 7 - Scoring

An every turn rule:
    now score is 5 minus the number of concerned things;
    if the location is concerned, decrement the score;
    if all of the supporters are concerned and the location is concerned, end the story;
    if none of the supporters are concerned and the location is not concerned, end the story finally.

The maximum score is 5.

When play begins, now score is 4.

Test me with "i / take off left shoe / get the glass / put the glass on the platter / get the tile / drop the tile / get the kettle / put the kettle on tile / sit on the blue armchair".

112. A Day For Fresh Sushi ★★★★

The following is an almost-completely-faithful rewrite of Emily Short's "A Day for Fresh Sushi", which was originally written using the (very different) Inform 6 programming language. The -- let us be honest and call it a gimmick -- of this game is the evil fish, who has some unpleasant remark to offer on pretty much every action. But the effect would wear off fast if he repeated himself, so these comments need to be single-use only.

Inform 7's repeated action syntax makes it much tidier to write the same scenario, so:

paste.png "A Day For Fresh Sushi" by Emily Short.

Use scoring.

The story headline is "Your basic surreal gay fish romance".

The Studio is a room. "[if visited]Decorated with Britney's signature flair. It was her innate sense of style that first made you forgive her that ludicrous name. And here it is displayed to the fullest: deep-hued drapes on the walls, the windows flung open with their stunning view of old Vienna, the faint smell of coffee that clings to everything. Her easel stands over by the windows, where the light is brightest.[otherwise]This is Britney's studio. You haven't been around here for a while, because of how busy you've been with work, and she's made a few changes -- the aquarium in the corner, for instance. But it still brings back a certain emotional sweetness from the days when you had just met for the first time... when you used to spend hours on the sofa...

You shake your head. No time for fantasy. Must feed fish.[end if]"

Instead of smelling the Studio:
    say "The evil fish notices you sniffing the air. 'Vanilla Raspberry Roast,' it remarks. 'You really miss her, don't you.'

You glance over, startled, but the fish's mouth is open in a piscine equivalent of a laugh. You stifle the urge to skewer the thing..."

Instead of jumping:
    say "'Er,' says the fish. 'Does that, like, EVER help??'"

Instead of going nowhere:
    say "You can't leave until you've fed the fish. Otherwise, he'll complain, and you will never hear the end of it."

The cabinet is an openable closed container in the Studio. It is fixed in place. "A huge cabinet, in the guise of an armoire, stands between the windows." The description is "Large, and with a bit of an Art Nouveau theme going on in the shape of the doors." Understand "armoire" as the cabinet.

Instead of looking under the cabinet for the first time:
    say "'Dustbunnies,' predicts the fish, with telling accuracy. It executes what for all the world looks like a fishy shudder. 'Lemme tell you, one time I accidentally flopped outta the tank, and I was TWO HOURS on the floor with those things STARING ME IN THE NOSE. It was frightening.'"

After opening the cabinet for the first time:
    say "'There ya go,' says the fish. 'The girl is getting WARMER.'"

After closing the cabinet for the first time:
    if the fish food is not found, say "'Ooh, what do you think, Bob? I think we're going to have to dock the girl a few points. HAVE ANOTHER LOOK, sweetcakes, there's a doll.'"

The cabinet contains some paints and some cloths. The description of the paints is "A bunch of tubes of oil paint, most of them in some state of grunginess, some with the tops twisted partway off."

After taking the paints for the first time:
    say "'Boy,' says the fish, apparently to himself, 'I sure hope that's some food she's finding for me in there. You know, the yummy food in the ORANGE CAN.'"

After examining the paints for the first time:
    say "'Tons of useful stuff in there,' hollers in the fish, in a syncopated burble."

The description of the cloths is "Various colors of drapery that Britney uses to set up backgrounds and clothe her models. She does a lot of portraiture, so this comes in handy. It's all a big messy wad at the moment. Organized is not her middle name." Understand "drapery" or "cloth" as the cloths. The indefinite article of the cloths is "a heap of". [see 3.17]

Instead of searching or looking under the cloths for the first time:
    now the player is carrying the fish food;
    now the fish food is found;
    say "Poking around the cloths reveals -- ha HA! -- a vehemently orange can of fish food."

Instead of showing the cloths to the fish:
    say "'What are you, some kind of sadist? I don't want to see a bunch of cloths! What kind of f'ing good, 'scuse my French, is that supposed to do me? I don't even wear pants for God's sake!'

He really looks upset. You start wondering whether apoplexy is an ailment common to fish."

After examining cloths for the first time:
    say "'Whatcha looking at? I can't see through the doors, you know.'"

There is a can of fish food. Understand "canister" as the can. The description is "A vehemently orange canister of fish food." The fish food can be found or hidden. The fish food is hidden.

Instead of giving the can to the fish:
    say "'I don't want the whole can, GeniusChyk. Just feed me and we'll ALL be happy, 'kay?"

Instead of showing the can to the fish:
    say "'That's the ticket, sweetie! Bring it on.'"

Instead of opening the can:
    say "'Oh, for--!' The evil fish breaks out in exasperation and hives. 'Screw the screwing around with the screwtop. SHE never has to do that.'

'Well, SHE is not here,' you reply. 'What do you suggest?'

'>FEED FISH<' says the fish promptly, making fishy faces and pointing at you with his fin. 'Simplicity. Try it.'"

Instead of inserting the can into something:
    say "'HelLLLOOO,' screams the fish. 'Whatever happened to FEEDING MEEE?'"

The easel is a supporter in the Studio. It is scenery. On the easel is a painting. Understand "portrait" or "image" as the painting.

The description of the painting is "Only partway finished, but you can tell what it is: Britney's mother. You only met the old woman once, before she faded out of existence in a little hospice in Salzburg.

In the picture, her hands are grasping tightly at a small grey bottle, the pills to which she became addicted in her old age, and strange, gargoyle-like forms clutch at her arms and whisper in her ears.

But the disturbing thing, the truly awful thing, is the small figure of Britney herself, down in the corner, unmistakable: she is walking away. Her back turned.

You thought she'd finally talked this out, but evidently not. Still feels guilty for leaving. You only barely stop yourself from tracing, with your finger, those tiny slumped shoulders..."

Instead of taking the painting, say "No, you'd better leave it. It'd freak her out if you moved it."

Before examining the painting for the first time:
    say "A ferocious banging from the aquarium attracts your attention as you go to look at the painting. 'Hey!' screams the fish. 'She doesn't like strangers looking at her paintings before they're DOONNNE!'

'Shut up, you,' you reply casually. 'I'm not a stranger.' But the fish puts you off a little bit, and your heart is already in your mouth before you see the painting itself...".

Instead of examining the painting more than once:
    say "Once is really enough. It's pretty much embedded in your consciousness now."

After doing something to the painting:
    say "'So what's it of?' asks the fish, as you turn away. 'She never asks if I want to see them, you know?'

'Her mother,' you respond without thinking.

'Yeah? Man. I never knew my mother. Eggs, that's the way to go.'"

The window is scenery in the Studio. The window can be openable. The window can be open. It is openable and closed. Understand "windows" as the window. The description of the window is "[if open]Through the windows you get a lovely view of the street outside. At the moment, the glass is thrown open, and a light breeze is blowing through.[otherwise]Through the windows, you get a lovely view of the street outside -- the little fountain on the corner, the slightly dilapidated but nonetheless magnificent Jugendstil architecture of the facing building. The glass itself is shut, however.[end if]"

After opening the window for the first time:
    say "'Thank god some air,' says the fish. 'Man, it was getting hard to breathe in here.' Two beats pass. 'Oh wait.'"

The table is scenery in the Studio. On the table is a vase. The vase is an open container. It is not openable.

The description of the table is "A monstrosity of poor taste and bad design: made of some heavy, French-empire sort of wood, with a single pillar for a central leg, carved in the image of Poseidon surrounded by nymphs. It's all scaley, and whenever you sit down, the trident has a tendency to stab you in the knee. But Britney assures you it's worth a fortune." The description of the vase is "A huge vase -- what you saw once described in a Regency romance as an epergne, maybe -- something so big that it would block someone sitting at the table from seeing anyone else also sitting at the table. But it does function nicely as a receptacle for hugeass bouquets of flowers."

Instead of looking under the table for the first time:
    say "'You're not going to find anything down there,' whines the fish. 'I mean, c'mon. It's the fricking floor. Please tell me you can see that. I can see that. I'm a myopic fish in a tank ten feet away and I can tell you there is nothing there but floor.'"

After examining the table:
    say "'That there is MY PA,' says the fish, pointing at the scaley triton figure with one fin."

Instead of inserting something which is not the bouquet into the vase:
say "'Okay, so, what were you, raised in a barn? Normal folks like to use that for flowers. Or so I've observed.'"

After inserting the bouquet into the vase for the first time:
    say "You settle the flowers into the vase and arrange them so that they look sprightly.

'Oooh,' says the fish. 'No one ever changes the plant life in HERE. It's the same seaw--'

'Cut me a break and cork it,' you reply tartly."

The player is carrying a telegram, a bouquet, and a lingerie bag. The player is wearing a chef hat.

The description of the telegram is "A telegram, apparently. And dated three days ago. [fixed letter spacing]TRIUMPH OURS STOP BACK SOON STOP BE SURE TO FEED FISH STOP[variable letter spacing]". [For printing options see 4.13.] Understand "yellow paper" as the telegram.

After examining the telegram for the first time:
    say "'So,' blubs the evil fish. 'How about it? Little food over here?'"

After examining the telegram:
    choose a random row in the Table of Insulting Fish Comments;
    say "[comment entry][paragraph break]".

Table of Insulting Fish Comments
comment
"'Yeah, yeah,' says the fish. 'You having some trouble with the message, there? Confused? Something I could clear up for you?'"
"'Oookay, genius kid has some troubles in the reading comprehension department.' The fish taps his head meaningfully against the side of the tank. 'I'm so hungry I could eat my way out, you get my meaning?'"
"'I'll translate for you,' screams the fish in toothy fury. 'It says GIVE FOOD TO FISH!! How much more HELP do you NEED???"

The description of the chef hat is "A big white chef hat of the kind worn by chefs. In this case, you. Just goes to show what a hurry you were in on the way out of the restaurant." Understand "big" or "white" or "chefs" or "chef's" as the chef hat. [Inform knows that this is clothing because the player starts out wearing it, so there's no need to say so separately.]

The aquarium is a transparent open container in the Studio. It is not openable. "In one corner of the room, a large aquarium bubbles in menacing fashion." The description of the aquarium is "A very roomy aquarium, large enough to hold quite a variety of colorful sealife -- if any yet survived." Understand "tank" as the aquarium.

The aquarium contains some gravel and some seaweed. Understand "little rocks" as the gravel. Understand "weed" as the seaweed. The description of the gravel is "A lot of very small grey rocks." The description of the seaweed is "Fake plastic seaweed of the kind generally bought in stores for exactly this purpose."

The examine containers rule does nothing when examining the aquarium.

After examining the gravel for the first time:
    say "The fish notices your gaze; makes a pathetic mime of trying to find little flakes of remaining food amongst the gravel."

After examining the seaweed for the first time:
    say "'Nice, hunh?' blubs the fish, taking a stabbing bite out of one just by way of demonstration. 'Look so good I could eat it.'"

The aquarium contains an animal called an evil fish. The description of the fish is "Even if you had had no prior experience with him, you would be able to see at a glance that this is an evil fish. From his sharkish nose to his razor fins, every inch of his compact body exudes hatred and danger."

Instead of taking the evil fish:
    say "The fish swims adroitly out of range of your bare hand. 'Hey,' he says, and the bubbles of his breath brush against your fingers. 'Count yourself lucky I don't bite you right now, you stinking mammal.'"

Instead of attacking the evil fish:
    say "Oh, it's tempting. But it would get you in a world of hurt later on."

Instead of kissing the evil fish:
    say "You're saving all your lovin for someone a lot cuddlier."

After examining the evil fish for the first time:
    say "The fish glares at you, as though to underline this point."

After examining the evil fish for the second time:
    say "'If you're looking for signs of malnutrition,' says the fish, 'LOOK NO FURTHER!!' And it sucks in its gills until you can see its ribcage."

An every turn rule:
    choose a random row in the Table of Fish Banter;
    say "[comment entry][paragraph break]".

Table of Fish Banter

comment

used

"'Hey, nice SKIN TONE,' shouts the evil fish. His words reach you in a spitting gurgle of aquarium water. 'You gone over to a pure eggplant diet these days?'"

0

"The evil fish is floating belly up! ...oh, curse. He was toying with you. As soon as he sees you looking, he goes back to swimming around."

0

"The evil fish darts to the bottom of the tank and moves the gravel around with his nose."

0

"The evil fish is swimming around the tank in lazy circles."

0

"The evil fish begins to butt his pointy nose against the glass walls of the tank."

0

The description of the bouquet is "Okay, so it's silly and sentimental and no doubt a waste of money, of which there is never really enough, but: you miss her. You've missed her since ten seconds after she stepped aboard the shuttle to Luna Prime, and when you saw these -- her favorites, pure golden tulips like springtime -- you had to have them." Understand "flowers" or "tulip" or "tulips" as the bouquet.

After examining the bouquet for the first time:
    say "'Oh, you shouldn't have,' says the fish. 'For me??'
    You just respond with a livid glare."

    Instead of smelling the bouquet for the first time:
        say "'Mmm-mm,' says the fish. 'Damn, I sure wish I had olfactory abilities. Hey, if I did, I might be even better at noticing the presence or absence of FOOD.'"

    The description of the lingerie bag is "You grant yourself the satisfaction of a little peek inside. You went with a pale, silky ivory this time -- it has that kind of sophisticated innocence, and it goes well with the purple of your skin. A small smirk of anticipation crosses your lips."

    After examining the lingerie bag for the first time:
        say "'What's in THERE?' asks the fish. 'Didja bring me take-out? I don't mind Chinese. They eat a lot of carp, but what do I care? I'm not a carp. Live and let live is what I s--'

'It's NOT take-out.' You stare the fish down and for once he actually backstrokes a stroke or two. 'It's PRIVATE.'"

After examining the lingerie bag for the second time:
    say "'If it's not take-out, I don't see the relevance!' shouts the fish. 'Food is what you want in this situation. Food for MEEEE.'"

Understand the command "feed" as something new.

Understand "feed [something]" as feeding.

Feeding is an action applying to one visible thing.

Check feeding:
    if the noun is not the evil fish, say "That doesn't make much sense." instead;
    if the player is not carrying the fish food, say "You need the fish food first." instead.

Carry out feeding:
    increment the score;
    say "Triumphantly, you dump the remaining contents of the canister of fish food into the tank. It floats on the surface like scum, but the fish for once stops jawing and starts eating. Like a normal fish. Blub, blub.[paragraph break]";
    say "[bold type] *** TWO HOURS LATER ***[roman type][paragraph break]'So,' Britney says, tucking a strand of hair behind your ear, 'where shall we go for dinner? Since I made the big bucks on this trip, it's my treat. Anywhere you like.'[paragraph break]'I've had a hankering all day,' you admit, as the two of you turn from the shuttle platform and head toward the bank of taxis. 'I could really go for some sashimi right now.'";
    end the story finally.

Before feeding the fish food:
    try feeding the evil fish instead.

When play begins:
    say "You're on the run. You've got a million errands to do -- your apartment to get cleaned up, the fish to feed, lingerie to buy, Britney's shuttle to meet-- [paragraph break]The fish. You almost forgot. And it's in the studio, halfway across town from anywhere else you have to do. Oh well, you'll just zip over, take care of it, and hop back on the El. This'll be over in no time.[paragraph break]Don't you just hate days where you wake up the wrong color?[paragraph break]".

The maximum score is 1.

Test me with "x fish / g / kiss fish / x aquarium / x gravel / x seaweed / i / x telegram / x bouquet / smell bouquet / x lingerie / g / x hat / x window / open window / x painting / g / x cabinet / open cabinet / x cloths / search cloths / open food / feed fish".

RB §7.4. Barter and Exchange

By default, Inform characters are a bit grudging about giving and sharing objects: they react with disinterest when they're shown things and refuse everything they're offered.

If we'd like to change this, we can simply remove the default "block giving" rule, as in

The block giving rule is not listed in the check giving it to rules.

If we do this, giving items to characters will have the result of moving our possessions to the other person's inventory. Of course, without more customization, the player may not ever be able to persuade the other character to return his possessions. Bribery ★★ demonstrates a scenario in which a character will accept gifts if they are interesting to him, and respond with a changed attitude to the player.

Barter Barter ★★★ expands further on this by allowing other characters to trade things with one another.

See also

Modifying Existing Commands for ways to allow the player to give or show things that he isn't currently holding
Actions on Multiple Objects for an implementation of giving that allows the player to offer multiple objects at once, where their combined value determines whether they are accepted
Money for ways to keep track of cash flow, physical money objects, and price negotiations

Examples

392. Bribery ★★

If we want to rewrite the functionality of a command that usually ends with a "block..." rule, we will have to begin by turning the blocking off.

paste.png "Bribery"

The block giving rule is not listed in the check giving it to rules.

As it happens, correct behavior is built into the GIVE command once "block giving" is turned off, so we do not have to write a replacement report or carry-out rule; the object will be transferred to the possession of the caterpillar. But we do want to adjust the action just a little so that our gift cheers up the recipient:

Carry out giving (this is the gratitude for gifts rule): improve the mood of the second noun.

Mood is a kind of value. The moods are hostile, suspicious, indifferent, friendly, and adoring. An animal has a mood. An animal is usually indifferent.

To improve the mood of (character - an animal):
    if the mood of character is less than friendly, now the mood of the character is the mood after the mood of the character.

Now whenever we give something to an animal, the animal will be pleased about the present. Of course, we might also want to add a check rule to giving, to see whether the offering is something the recipient really wants:

Check giving (this is the polite refusal of unwanted objects rule):
    unless the noun interests the second noun:
        say "[The second noun] disdainfully refuses [the noun]." instead.

To decide whether (item - a thing) interests (character - a person):
    if the character has the item, no;
    if the item is edible, yes;
    no.

Instead of showing something to someone:
try giving the noun to the second noun.

There is already a perfectly workable report rule that will describe what happens when we give something to someone, but let's say we want to report on the recipient's changed mood, too:

After giving something to someone:
    say "You give [the noun] to [the second noun], who appears mollified and is now merely [mood of the second noun]."

And the rest is all scenario:

The Leafy Branch is a room. "You stand on smooth bark dappled by sunlight. The scent-trail runs forward to home.

The branch continues forward and backward from here, and a stem extends forward-up."

Instead of going south in Leafy Branch, say "You must not back down! The scent trail leads onward!"

The Very Hungry Caterpillar is a hostile animal in the Leafy Branch. "[The Caterpillar] looks [mood]." Instead of examining the Caterpillar, say "[The caterpillar] appears [mood]."

The player carries an edible thing called a peanut crumb. The carrying capacity of the player is 1. After taking something, say "You lift [the noun], though it is nearly your own size."

Instead of going north in the presence of a hostile caterpillar:
    say "[The Caterpillar] moves to block your exit, glaring down at you with all the bristles on its skin extended to full size."

Instead of going north in the presence of a suspicious caterpillar:
    say "[The Caterpillar] moves to block your exit, though it might allow you past if you offered further tribute."

The Leaf Face is above the branch. "The smooth and shiny surface of the leaf extends forward from here, but you have lost the scent-trail. This is not the way home." The pear fragment is an edible thing in Leaf Face. The dead aphid is a thing in Leaf Face.

The Twig is north of Leafy Branch. "The scent-trail is weak but not entirely gone, and you pursue it faithfully..."

After going to the Twig:
    say "The scent-trail is weak but not entirely gone, and you pursue it faithfully...";
    end the story finally.

Understand "forward-up" as up. Understand "forward" as north. Understand "backward" as south. Understand "backward-down" as down.

Test me with "forward / give crumb to caterpillar / forward / forward-up / get aphid / get fragment / down / give aphid to caterpillar / drop aphid / forward-up / get fragment / down / give fragment / forward".

207. Barter Barter ★★★

By default, if we make no modifications, telling one player to give something to another will fail, even if persuasion succeeds. This is because the default behavior of the GIVE command is interrupted by the "block giving rule" -- since in many cases we do not want people to exchange objects freely.

However, suppose that we do want characters to be able to exchange articles freely: we allow persuasion to succeed and turn off the "block giving rule".

paste.png "Barter Barter"

The block giving rule is not listed in the check giving it to rules.

A persuasion rule for asking people to try giving: persuasion succeeds.

The Trading Post is a room.

Meriwether Lewis is a man in the Trading Post. He carries a fluffy handmade quilt and a bag of beans. The beans are edible.

William Clark is a man in the Trading Post. He carries leather slippers, a journal, and a loaf of bread. The bread is edible. The slippers are wearable.

Instead of examining someone:
    say "[The noun] is carrying [the list of things carried by the noun]."

And now we might want to implement a way to keep track of whether the recipient character wants what's being offered:

Check someone trying giving something to someone (this is the sneering refusal rule):
    if the second noun dislikes the noun, stop the action.

Unsuccessful attempt by someone trying doing something:
    if the reason the action failed is the sneering refusal rule, say "'Would you care for [the noun]?' [the person asked] asks solicitously of [the second noun].

But [the second noun] refuses [the noun] disdainfully.";
    otherwise say "[The person asked] just appears bewildered by this improbable instruction."

Distaste relates one person to various things. The verb to dislike means the distaste relation.

Clark dislikes the beans. Lewis dislikes the bread.

Since we've defined this as a relation, we could change what the characters like and dislike during the course of the game, freely; for instance, characters might grow hungry and suddenly like all the edible articles.

Test me with "x lewis / x clark / clark, give the slippers to lewis / clark, give the bread to lewis".

RB §7.5. Combat and Death

Not all characters are friendly, and there are times when we may want to include a fight sequence. There are a number of ways to approach this, depending on whether we want to offer the player a random outcome, a predetermined one, or a combat sequence that depends partly on strategy or on having the proper equipment.

Lanista 1 demonstrates randomized combat in the style of a role-playing game. The player has a partially random chance of doing any given amount of damage; both the player and his opponent have hit points, and whichever one runs out first dies. Lanista 2 ★★ continues this idea, but includes weapons that affect the amount of of damage done. Red Cross by itself implements a command that we might use to find out how strong characters are at the moment.

A word of warning about designing such sequences: a player who gets a roll he doesn't like always has the option of UNDOing a turn and re-rolling. This means that he can always win a random battle sooner or later; bad luck only means that it takes him longer (so he gets more bored and irritated as he plays through). It is possible to turn off UNDO implementation with

Use UNDO prevention.

...but there is a good chance that this will irritate players in itself. Role-playing-style combat scenarios need careful design, lest they actively make a story less fun.

In a slightly more realistic setting, combat leaves physical remains behind, unless we're wielding some kind of futuristic weapon that evaporates our opponents entirely: Puff of Orange Smoke ★★ demonstrates characters who leave corpses behind when they die, while Technological Terror ★★★ more tamely explodes robots into numerous component parts.

Finally, we can imagine some scenarios in which, instead of allowing characters to strike at each other for random damage, we want to introduce an element of strategy. Don Pedro's Revenge ★★★ shows the rudiments of a system in which the characters can make different kinds of attack depending on where they are in a room filled with perches, barrels, and other swashbuckler props.

See also

Saving and Undoing for more discussion of handling random behavior in games

Examples

131. Lanista 1

paste.png "Lanista, Part One"

The Arena is a room. "Sand, blood, iron. These festivals are normally held on hot days, but the sun has gone behind a cloud and fat drops of rain now and then spatter the arena floor." The gladiator is a man in the Arena. "A bare-chested Scythian gladiator faces you, wielding a trident."

We start by recording, for each person, a maximum number of points of damage the person can sustain when starting from health, and the current number of points remaining. In the tradition of role-playing games, these are referred to as hit points.

A person has a number called maximum hit points. A person has a number called current hit points.

The maximum hit points of the player is 35. The maximum hit points of the gladiator is 25.

The current hit points of the player is 35. The current hit points of the gladiator is 25.

Now our rule for the actual attack. We want first to calculate how much damage the player's attack does, inflict that damage, and remove the enemy if he's dead; then, if he doesn't die, the enemy counter-attacks, also for a randomized amount of damage, and if this kills the player, the game ends in defeat.

Instead of attacking someone:
    let the damage be a random number between 2 and 10;
    say "You attack [the noun], causing [damage] points of damage!";
    decrease the current hit points of the noun by the damage;
    if the current hit points of the noun is less than 0:
        say "[line break][The noun] expires, and is immediately carried away by the Arena slaves!";
        now the noun is nowhere;
        end the story finally;
        stop the action;
    let the enemy damage be a random number between 2 and 10;
    say "[line break][The noun] attacks you, causing [enemy damage] points of damage!";
    decrease the current hit points of the player by the enemy damage;
    if the current hit points of the player is less than 0:
        say "[line break]You expire!";
        end the story.

This last bit is a refinement to help the player keep track of how the contest is going:

When play begins:
    now the left hand status line is "You: [current hit points of player]";
    now the right hand status line is "Gladiator: [current hit points of gladiator]".

Test me with "hit gladiator / g / g / g".

191. Red Cross

paste.png "Red Cross"

Diagnosing is an action applying to one visible thing. Understand "diagnose [something]" as diagnosing.

Check diagnosing:
    if the noun is not a person, say "Only people can have diagnoses." instead.

Carry out diagnosing:
    say "You're not a medical expert."

Instead of diagnosing the player:
    say "You feel fine!"

The Clinic is a room. Fred is a man in the Clinic. The player carries a tongue-depressor.

Test me with "diagnose me / diagnose fred / diagnose tongue-depressor".

201. Puff of Orange Smoke ★★

Suppose we want to let the player kill characters, leaving behind corpses.

paste.png "Puff of Orange Smoke"

Paraguay is a room. Bolivia is north of Paraguay. Lydia is a woman in Paraguay. "Lydia is, as usual, here." The description of Lydia is "Long, long legs and a sarcastic attitude." Instead of touching Lydia: say "'Watch it, sailor,' she snaps."

A body is a kind of thing. A body is a part of every person. Instead of touching a body: say "[The noun] is grotesquely inert."

The description of Lydia's body is "Long, long legs and no attitude at all." The initial appearance of Lydia's body is "Lydia's corpse is sprawled at your feet."

Using our "part of every person..." line, we've conveniently assigned one body per person. Since we're going to separate people from their bodies when the bodies die, though, we also want a more permanent relation that will help us keep track of which bodies used to belong to which people:

Spirit-possession relates one person to one body. The verb to be owner of means the spirit-possession relation.

When play begins:
    repeat with victim running through people:
        let the corpse be a random body which is part of the victim;
        now the victim is owner of the corpse.

When Lydia is alive, we want >TOUCH LYDIA'S BODY to mean the same thing as >TOUCH LYDIA, so we use the setting action variables rules as a convenient point at which to reassign the action:

Setting action variables when the noun is a body which is part of a person (called owner):
    now the noun is the owner.

Setting action variables when the second noun is a body which is part of a person (called owner):
    now the second noun is the owner.

This doesn't change Inform's idea about what action is being performed; just about the object it's being performed on. The rest of the action will now proceed as if the player had typed >TOUCH LYDIA.

Along similar lines, once Lydia is dead, we want >MOVE LYDIA to mean >MOVE LYDIA'S BODY if the body is in view:

Setting action variables when the noun is a dead person and the noun is owner of a visible body (called the mortal remains):
    now the noun is the mortal remains.

The trick is, though, that >MOVE LYDIA will only be understood if there is something called Lydia that the player can see and refer to, even after she's dead. There are various ways to do this, but the least painful here will be to make the deceased Lydia permanently visible, by putting her in an always-accessible backdrop. The backdrop itself will never be mentioned in the game, and we should make its name something that the player is unlikely to type casually; we don't want the player to interact with it directly. So:

The worldview is a privately-named backdrop. It is everywhere. The spirit-world is a privately-named transparent closed unopenable container. It is part of the worldview.

Definition: a person is dead if he is in the spirit-world.

It's also possible that the player will type something like >X LYDIA when Lydia's corpse is not in view, so we should have an appropriate answer to that as well:

Before doing something to a dead person:
    say "[The noun] is dead; or had you blocked that out?" instead.

Because the before rules happen after the setting action variables rules, this will only ever happen if the corpse is not visible.

Now we define the attack itself, which should discard the body, move the spirit to its eternal resting place, and describe the event to the player:

Instead of attacking someone:
    let the corpse be a random body which is part of the noun;
    move the corpse to the location;
    move the noun to the spirit-world;
    say "With a single blow, you rid the world of [the noun]."

And finally a trick borrowed from the chapter on understanding, so that we can refer to "Lydia's body" while Lydia is alive, but "Lydia's corpse" only after Lydia has died:

Understand "corpse" as a body when the item described is not part of a person.

Test me with "x body / x lydia's body / touch lydia's body / x corpse / kill lydia / look / x lydia's body / x lydia's corpse / x corpse / x lydia / touch lydia / lydia, hello / n / x lydia / touch lydia / lydia, hello".

293. Lanista 2 ★★

Back in the chapter on randomization, we explored a way to create a randomized combat system. That system didn't allow for multiple weapons, though. Here we explore how to create an ATTACK IT WITH action that will let the player choose between weapons with different maximum powers.

We're also going to rewrite that original "instead of attacking:" rule into an attacking it with action that can be performed equally by the player or by any of the player's enemies.

paste.png "Lanista, Part Two"

The Arena is a room. "Sand, blood, iron. These festivals are normally held on hot days, but the sun has gone behind a cloud and fat drops of rain now and then spatter the arena floor." The gladiator is a man in the Arena. "A bare-chested Scythian gladiator faces you, wielding [a list of weapons carried by the gladiator]."

Section 1 - Hit Points

A person has a number called maximum hit points. A person has a number called current hit points.

The maximum hit points of the player is 35. The maximum hit points of the gladiator is 25.

In our simpler version of this example we set the current hit points by hand, but in a game with many characters this would get dull and repetitive, so here we'll use a "when play begins" to set all current hit point values automatically to maximum:

When play begins:
    repeat with victim running through people:
        now the current hit points of the victim is the maximum hit points of the victim.

Definition: a person is dead if his current hit points are less than 0.

Section 2 - Diagnosis

Diagnosing is an action applying to one visible thing. Understand "diagnose [something]" as diagnosing.

Check diagnosing:
    if the noun is not a person, say "Only people can have diagnoses." instead.

Carry out diagnosing:
    say "[if the noun is the player]You have[otherwise][The noun] has[end if] [current hit points of the noun] out of a possible [maximum hit points of the noun] hit points remaining."

Section 3 - Weapons

A weapon is a kind of thing. A weapon has a number called the maximum damage. The maximum damage of a weapon is usually 4.

The gladiator carries a weapon called a trident. The maximum damage of the trident is 5. The gladiator carries a weapon called a net. The maximum damage of the net is 1.

The player carries a weapon called a mace. The maximum damage of the mace is 3.

Section 4 - Attacking it with

In our new system, we want to specify what is being used for an attack. This means that we need to create a new "attacking it with" action, and also that we should disable the existing "attacking..." command.

Here's why: If we leave the default attack command in place, Inform will continue to accept commands like >ATTACK GLADIATOR, but reply foolishly with the default "Violence is not the answer..." response.

A somewhat better approach would be to change the reply of >ATTACK GLADIATOR to say something like "You must specify a weapon to attack with." But this is still less than ideal, because it means that the player has to then rewrite his entire command. If, on the other hand, we take out "ATTACK GLADIATOR" entirely, the game will always prompt "What do you want to attack the gladiator with?" -- which teaches the player the correct command structure for this particular game, and avoids pretending to understand any command that is not meaningful within this game.

This is a little bit of work because ATTACK has a lot of synonyms in the default library, but if we look through the actions index we can find them all:

Understand the commands "attack" and "punch" and "destroy" and "kill" and "murder" and "hit" and "thump" and "break" and "smash" and "torture" and "wreck" as something new.

Now we make our new command:

Attacking it with is an action applying to one visible thing and one carried thing. Understand "attack [someone] with [something preferably held]" as attacking it with.

Note that we've specified "one carried thing", because we want the player to pick up a weapon to use if necessary. And now we assign all the old attack vocabulary to apply to the new command:

Understand the commands "punch" and "destroy" and "kill" and "murder" and "hit" and "thump" and "break" and "smash" and "torture" and "wreck" as "attack".

This may seem counter-intuitive, but order of source code matters here: we first get rid of the old, default vocabulary, then define our new action, then make the vocabulary apply to that new action. Inform will now understand >HIT GLADIATOR WITH TRIDENT, >BREAK GLADIATOR WITH TRIDENT, and so on.

Our new action is also a perfect place to use an action variable: we're going to need to choose an amount of damage done and refer to that several times in our action rules. So let's set that up first:

The attacking it with action has a number called the damage inflicted.

Setting action variables for attacking something with something:
    if the second noun is a weapon:
        let the maximum attack be the maximum damage of the second noun;
        now the damage inflicted is a random number between 1 and the maximum attack.

Check an actor attacking something with something (this is the can't attack with something that isn't a weapon rule):
    if the second noun is not a weapon:
        if the actor is the player, say "[The second noun] does not qualify as a weapon.";
        stop the action.

Check an actor attacking something with something (this is the can't attack a non-person rule):
    if the noun is not a person:
        if the actor is the player, say "[The noun] has no life to lose.";
        stop the action.

Carry out an actor attacking something with something (this is the standard attacking it with a weapon rule):
    decrease the current hit points of the noun by the damage inflicted;
    if the noun is dead:
        now the noun is nowhere.

Though our checks and carry-out rules are similar regardless of who is acting, we're going to want actions to be described differently for different actors, so we'll use separate "report attacking" and "report someone attacking" rules. We'll also make some special cases for when the character has died as a result of the attack:

Report attacking a dead person with something (this is the death-report priority rule):
    say "You attack with [the second noun], killing [the noun]!" instead.

Report attacking someone with something (this is the normal attacking report rule):
    say "You attack [the noun] with [the second noun], causing [damage inflicted] point[s] of damage!" instead.

Report someone attacking the player with something when the player is dead (this is the player's-death priority rule):
    say "[The actor] attacks you with [the second noun], finishing you off!";
    end the story;
    stop the action

Report someone attacking the player with something (this is the standard report someone attacking the player with rule):
    say "[The actor] attacks you with [the second noun], causing [damage inflicted] point[s] of damage!" instead.

Report someone attacking something with something (this is the standard report attacking it with rule):
    say "[The actor] attacks [the noun] with [the second noun], causing [damage inflicted] point[s] of damage!" instead.

When play begins:
    now the left hand status line is "You: [current hit points of player]";
    now the right hand status line is "Gladiator: [current hit points of gladiator]".

Every turn (this is the gladiator-attack rule):
    if the gladiator is not dead, try the gladiator attacking the player with a random weapon which is carried by the gladiator.

Test me with "hit gladiator with mace / kill gladiator / drop mace / attack gladiator / attack gladiator with mace / g / g".

Those devoted to role-playing will note that our form of randomization is still pretty naive: most RPG systems use multiple dice in order to create more interesting probability curves. For a system that simulates actual dice-rolling, see the full "Reliques of Tolti-Aph" game.

113. Don Pedro's Revenge ★★★

Suppose our game features a detailed simulated combat between the player character and his opponent. He might have several weapons available, and several types of attack available; and at any given time he might be perched up in the rigging of his ship, standing on the open deck, or boxed in between some barrels. His options will vary depending on his position, and obviously it would detract from the pacing to make the player keep LOOKing in the middle of combat in order to remind himself where he is. Instead, we'll roll this information into the command prompt:

paste.png "Don Pedro's Revenge"

The Deck of the Helene Marie is a room. "The two crews are embattled all around you, but your attention is reserved for your particular enemy: Don Pedro."

Table of Random Prompts

position

prompt

boxed

"So securely boxed-in that you can really only parry or thrust, you try to "

boxed

"Trapped between your barrels, you decide to "

perched

"Able to slice at your attackers but not to advance or retreat, you choose to "

perched

"Perched up here with the advantage of height (but little mobility), you attempt to "

free

"Out on the open deck with no impediments, free to advance or retreat, you decide to "

When play begins: reset the prompt.

Every turn: reset the prompt.

To reset the prompt:
    sort the Table of Random Prompts in random order;
    repeat through the Table of Random Prompts:
        if the position entry is the placement of the player:
            now the command prompt is prompt entry;
            stop.

After reading a command: say conditional paragraph break.

A placement is a kind of value. The placements are boxed, perched, free. The player has a placement. The player is free.

Understand "retreat" or "parry" as retreating. Retreating is an action applying to nothing.

Check retreating:
    if the player is perched, say "You can't move backward or parry very successfully from this position." instead.

Carry out retreating:
    now the player is boxed;
    say "You protect yourself, but end up wedged in between two barrels."

Understand "thrust" or "advance" as advancing. Advancing is an action applying to nothing.

Check advancing:
    if the player is perched, say "You can't move forward from here, only slash." instead.

Carry out advancing:
    now the player is free;
    say "You push forward aggressively, making your way to the open deck."

Instead of jumping:
    now the player is perched;
    say "You leap and swing yourself boldly up into the rigging, leaving your attackers beneath you."

Instead of jumping when the player is perched:
    now the player is free;
    say "You leap down from your position, into the middle of the deck."

Test me with "advance / jump / advance / retreat / jump / retreat / retreat / advance".

Of course, this won't be much fun until we also provide the player with a few weapons, some more fighting maneuvers, and, most of all, a Don Pedro to defeat.

127. Technological Terror ★★★

paste.png "Technological Terror"

The Decomposition Ray Gun is a thing carried by the player.

First we need to define our shooting action:

Shooting it with is an action applying to two things.

Check shooting something with something:
    if the player is not carrying the Ray Gun, say "You are pathetically unarmed!" instead;
    if the second noun is not the Ray Gun, say "[The second noun] does not fire." instead;
    if the noun is the Ray Gun, say "Nice trick if you can do it!" instead;
    if the noun is the player, say "That would be disastrous!" instead.

Next, some grammar to allow the player to use this action:

Understand "shoot [gun] at [something ungunlike]" as shooting it with (with nouns reversed).

Definition: a thing is ungunlike if it is not the gun.

Understand "shoot [something ungunlike] with [gun]" as shooting it with. Understand "shoot [something] with [something]" as shooting it with.

Understand "shoot [something] at [something]" as shooting it with (with nouns reversed). Understand "fire [gun] at [something ungunlike]" as shooting it with (with nouns reversed). Understand "fire at [something ungunlike] with [gun]" as shooting it with. Understand "fire at [something] with [something]" as shooting it with.

Strictly speaking, we only need these last grammar lines (with "understand shoot something...") in order to define an action that the player can take. Adding more grammar lines means that Inform will try to match the most specific ones first, which is useful when the player types something ambiguous and there is one choice that obviously fits this action better than the others. See the chapter on Understanding for a further discussion.

Here we get to use "now..." to give it its destructive effect:

Carry out shooting something with something:
    say "ZAP! [The noun] twinkles out of existence! [if something is part of the noun][The list of things which are part of the noun] clatter to the ground! [end if][paragraph break]";
    now every thing which is part of the noun is in the location;
    now the noun is nowhere.

The Deathbot Assembly Line is a room. "Here is the heart of the whole operation, where your opponents are assembled fresh from scrap metal and bits of old car." The dangerous robot is a thing in the Assembly Line. "One dangerous robot looks ready to take you on!" A robotic head, a drill arm, a needle arm, a crushing leg and a kicking leg are parts of the dangerous robot.

Instead of examining something when something is part of the noun:
    say "[The noun] consists of [a list of things which are part of the noun]."

Test me with "x robot / shoot robot / fire at kicking leg / shoot gun at drill arm / look".

RB §7.6. Getting Started with Conversation

Traditionally, conversation is one of the most difficult things to program in interactive fiction, because of the number of factors affecting the outcome of everything the player does. While it's acceptable for >EXAMINE POT to produce the same response every time the player types it, it's a bit less acceptable for ASK JOE ABOUT HIS ADULTERY to make Joe react the same way every time.

Conversation implementations often need to keep track of a lot of information: what else is going on in the model world, what the character knows, what plot phase we've reached, what mood the character is in, what else we've recently been talking about, whether we've said the same thing before (and how many times); and so on. Later in this chapter we will look at ways to model character knowledge and mood.

Then, too, we have the problem of how the player communicates his conversational intentions to the story. Technology has not yet advanced to the point where a player can simply type in remarks in full natural English and have the character detect the significance, emotional tone, and subtext, if any: so we can't have RACHEL, THIS DESSERT TASTES LIKE FEET or WILL, LOOK! OUR SINISTER METAL FOES ARE APPROACHING! or BOSS, I WOULD BE DELIGHTED TO FILE ANOTHER TPB REPORT.

The challenge is to create an interface that is both easy for the player to use and expressive enough to be interesting. We will look at some of the common solutions in "Saying Complicated Things".

The examples in the following sections point out ways to approach common conversation problems. None of them will offer an adequate system if we want to write a very conversationally rich story, however. This is partly because a thorough conversation system requires quite a lot of code in its own right. It's also partly because there is no one right solution to the problem of conversation design. Different games will have quite different requirements. When making decisions about a new story we have planned, it may be useful to glance through the conversation extensions available for Inform: there are quite a few, offering a range of different interfaces. Even if none is exactly suited for our needs, they may suggest ways to solve particular implementation challenges.

At the other end of the scale, though, there are times when Inform's default implementation is too complicated for what we want to do: so we will start with ways to simplify conversation, before moving to all the exotic complexities.

Before we get into these details, though, we have a couple of examples that are literally about getting started with a conversation: Mimicry ★★★ introduces the feature that we must greet other characters before beginning to speak to them; The Gorge at George corrects the player's attempts to use a TALK TO command where a different mode of interaction is appropriate instead.

Examples

330. The Gorge at George

paste.png "Gorge at George"

The Dusty Lot is a room. "A few miles up the road from the concert venue, but at least it's cheap to park here."

The motorcyclist is a man in the Dusty Lot. "A man clad in [a list of things worn by the motorcyclist] leans against his Harley and watches you without saying anything." The Harley is scenery in the Lot. The motorcyclist wears a black leather jacket and shades. Understand "man" or "guy" as the motorcyclist.

Understand "talk to [someone]" as a mistake ("To start a conversation, try to ASK [the noun] ABOUT something or TELL [the noun] ABOUT something.").

Instead of asking the motorcyclist about something:
    say "He smirks cryptically."

Instead of telling the motorcyclist about something:
    say "This does not seem to interest him much."

Test me with "talk to motorcyclist / ask motorcyclist about himself / tell motorcyclist about me".

110. Mimicry ★★★

Suppose we want to add a sense of some conversational flow, so that the player is forced to acknowledge the presence of people before beginning detailed conversations with them. We collect all speech actions into a single category:

paste.png "Mimicry"

Asking someone about something is speech. Telling someone about something is speech. Answering someone that something is speech. Asking someone for something is speech.

And then write a general rule.

Before speech in the presence of an ungreeted person: try waving hands.

One complication is that "asking someone to try doing something", which describes commands such as FRED, GO SOUTH, cannot be made into a kind of action. This requires its own rule:

Before asking someone to try doing something in the presence of an ungreeted person: try waving hands.

Now we define what greetings are going to look like:

Check waving hands:
    unless the player can see someone who is not the player, say "You are alone." instead.

Carry out waving hands:
    say "You nod hello to [the list of ungreeted people who can be seen by the player].";
    now every ungreeted person who can be seen by the player is greeted.

The report waving hands rule is not listed in the report waving hands rulebook.

Because of the way we've defined the command, this will now also work if the player waves.

A person can be greeted or ungreeted. A person is usually ungreeted. The player is greeted.

And now the scenario:

The International Convention of Mimes is a room. Lester, Harold, Geoff, Kwame, and Peter are men in the Convention. Elouise is a woman in the Convention. The Invisible Box is an enterable container in the Convention. "You can detect, from the way people keep leaning on it, an invisible box in the middle of the room."

Lester carries a bowler hat.

Instead of speech in the presence of someone:
    describe poor reception.

Definition: a person is other if it is not the player.

At 9:01 AM:
    move Phineas to the location; say "A mime called Phineas appears from the non-existent bathroom."

Phineas is a man.

A persuasion rule:
    describe poor reception;
    persuasion fails.

To describe poor reception:
    if the player is in the Invisible box,
        say "Everyone convulses with silent laughter as you try to shout from within the invisible box.";
    otherwise
        say "You attempt to convey your meaning with gesture and interpretive dance, but [the list of visible other people] scorn[if the number of visible other people is 1]s[end if] your performance, refusing to respond."

Test me with "ask lester about work / lester, east / ask lester for bowler / lester, nice not talking to you / get in box / ask lester for hat / phineas, east".

RB §7.7. Saying Simple Things

There are times when even the commands ASK and TELL are overkill: sometimes the player doesn't have much information to offer, so TELL is never useful, for instance. If we don't want to make any distinction between modes of conversation, we can conflate the actions so that ASK LUCIUS ABOUT OLLIVANDER, TELL LUCIUS ABOUT OLLIVANDER and LUCIUS, OLLIVANDER all do the same thing: see Sybil 1.

If we are frequently permitting the player to say things like LUCIUS, OLLIVANDER as shorthand for "talk to Lucius about Ollivander", then we may also want to allow LUCIUS, OLLIVANDER? This makes the player character seem a bit slow (or at least Laconic), but it is an effective interface in some cases. The trick is that the question mark at the end of the command may prevent Inform from recognizing the keyword; should that problem arise, we may want to use Punctuation Removal to erase question marks from the player's command before attempting to interpret it.

Along the same lines, there are situations in conversation where similar commands do not correspond to the same actions within Inform; if we're careless about this, we may force the player to guess which vocabulary we want him to use, which is always vexing. Some cases to look out for:

Inform has actions for "saying yes" and "saying no". Sometimes this is useful, but sometimes we want YES and SAY YES TO FRED to do the same thing. Sybil 2 ★★ shows how to roll these responses into one; Proposal ★★ expands on the idea to show more ways in which a player could reasonably answer a question put by another character.

Again, if we want ASK SYBIL ABOUT CAKE to do the same thing as SHOW CAKE TO SYBIL, we might use the technique in Nameless ★★ to make objects into valid topics of conversation, and to make ASK and SHOW behave the same way.

Finally, if we want to be able to ASK and TELL an inanimate object -- say, a computer -- about something, we may use the extension Inanimate Listeners to add this capability.

See also

Remembering, Converting and Combining Actions for ways to redirect one conversation command to another conversation topic
Varying What Is Read for a way of asking the player trivia questions that he can answer only on the next turn

Examples

92. Sybil 1

Sometimes we do not particularly want to deal with all the variations on asking, telling, or answering someone something, but want to direct everything to a single conversational command:

paste.png "Consulting the Oracle"

The Grove is a room. In the Grove is a woman called the Sybil.

Instead of telling someone about something, try asking the noun about it. Instead of answering the noun that something, try asking the noun about it.

Instead of asking the Sybil about "persians", say "She nods gravely."

And similarly, a difference between GIVE and SHOW is sometimes overkill:

Instead of showing something to someone, try giving the noun to the second noun.

The player carries a coin. Instead of giving the coin to the Sybil: move the coin to the Sybil; say "She accepts with a smile."

It is also often the case that we want to accept more than one form of a term. For instance

Instead of asking the Sybil about "Darius/king", say "Her smile unnerves you."

will match either "Darius" or "king". If necessary, we can go a step further and define our own token to match a variety of phrases, like this:

Understand "Athenians/Spartans/Greeks" or "hoplite army/forces" as "[Greeks]". Instead of asking the Sybil about "[Greeks]", say "She looks encouraging."

The token "[Greeks]" will match all of "Athenians", "Spartans", "Greeks", "hoplite army", or "hoplite forces". It will not match "hoplite" or "forces" alone; it is important to note that the / divides individual words which are understood equivalently, but does not define entire phrases as equivalent. More about how Inform understands specific phrases can be found in the chapter on Understanding.

Test me with "test one / test two".

Test one with "ask sybil about persians / tell sybil about persians / sybil, persians / ask sybil about darius / ask sybil about king".

Test two with "ask sybil about greeks / ask sybil about athenians / ask sybil about hoplite army / ask sybil about hoplite forces / give the coin to the sybil".

93. Sybil 2 ★★

Inform already understands YES, NO, and SORRY as commands in their own right, which can make things a little sticky when we want a character to ask a question of the player. The most important thing is not to cover some of the possible phrasings while ignoring others.

paste.png "Replies"

The Grove is a room. In the Grove is a woman called the Sybil.

Instead of asking the Sybil to try saying no: try saying no. Instead of asking the Sybil to try saying yes: try saying yes. Instead of asking the Sybil to try saying sorry: try saying sorry.

Instead of answering the Sybil that "yes", try saying yes. Instead of answering the Sybil that "no", try saying no. Instead of answering the Sybil that "sorry", try saying sorry.

Instead of saying yes in the presence of the Sybil:
    say "She looks interested."

Instead of saying no in the presence of the Sybil:
    say "She looks annoyed."

Instead of saying sorry in the presence of the Sybil:
    say "She looks bored."

The complexity arises from the fact that we want to handle both YES and SYBIL, YES. If we only had the latter, 'yes' would be treated as a text given to the Sybil, just as in the commands SAY YES TO SYBIL or ANSWER YES. But because we have defined it as a command (so that the player can use it independently), SYBIL, YES is understood as an order to the Sybil to do the YES action.

Fortunately, we can redirect everything, as here, so that the results wind up the same.

And if we want yet another variation not covered by the Inform standard:

Understand "tell [someone] [text]" as answering it that. Understand "tell [someone] that [text]" as answering it that.

But that is a matter for a later chapter.

Test me with "yes / sybil, yes / say yes to sybil / answer yes / tell sybil yes / no / sybil, no / say no to sybil / answer no / tell sybil no / sorry / sybil, sorry / say sorry to sybil / answer sorry / tell sybil sorry".

171. Proposal ★★

Suppose we want to ask the player a question where he might say yes or no in response. There are two possible forms of this: the modal question where the player must pick one to proceed, and the non-modal question where he might also type other verbs.

paste.png "Proposal"

The story genre is "A Worked Example about Yes/No Questions".

Section 1 - Asking a Modal Yes/No Question

When play begins:
    say "Do you like Mr Spruce? ";
    if player consents, now Spruce is handsome;
    otherwise now Spruce is ugly;
    say paragraph break.

Section 2 - Mr Spruce's Non-Modal Question

Use full-length room descriptions.

The Conservatory is a room. "You are in a room full of plants."

Mr Spruce is a man in the Conservatory. Mr Spruce can be apprehensive or calm. Mr Spruce is calm. Mr Spruce can be handsome or ugly.

At 9:02 AM: say "Mr Spruce flings himself to his knees and implores you to become his lawfully wedded wife.";
    now Mr Spruce is apprehensive;
    Mr Spruce gives up in two minutes from now.

At the time when Mr Spruce gives up:
    say "Mr Spruce sighs heavily, seeing that you don't intend to reply. 'Never mind, my dear, I'll ask later. Perhaps I should have spoken to your Papa first... yes, a gently-bred female... no wonder...'";
    now Mr Spruce is calm;
    Mr Spruce departs in one minute from now.

At the time when Mr Spruce departs:
    if the player can see Mr Spruce, say "Mr Spruce takes his leave of you.";
    otherwise say "Mr Spruce pokes his head in to say that he is leaving.";
    end the story saying "Well, that is over..."

Instead of saying yes in the presence of an ugly apprehensive Mr Spruce:
    now Mr Spruce is calm;
    say "Remembering what your mother said to you about the stock exchange and Dear Papa, you close your eyes and accept Mr Spruce.";
    end the story saying "Alas for your maiden hopes."

Instead of saying yes in the presence of a handsome apprehensive Mr Spruce:
    now Mr Spruce is calm;
    say "You are silent with delight for a moment before you say yes, yes!";
    end the story saying "How Genevieve Stubbs will cry!"

Instead of saying no in the presence of an ugly apprehensive Mr Spruce:
    now Mr Spruce is calm;
    say "Gently you inform Mr Spruce that it is impossible. He seems less deflated than you had expected.";
    end the story saying "Odd, that..."

Instead of saying no in the presence of a handsome apprehensive Mr Spruce:
    now Mr Spruce is calm;
    say "You lower your eyes and refuse petulantly, hoping to stir him to a more ardent repetition of these same requests. But then -- alack! -- he says 'I see how it is!' in a strangled voice, and strides from the room!";
    end the story saying "A fatal error!"

And since the player might SAY YES TO SPRUCE, we had better reroute the relevant options:

Instead of answering Mr Spruce that "no", try saying no.

Instead of answering Mr Spruce that "yes", try saying yes.

Instead of asking Mr Spruce to try saying yes, try saying yes.

Instead of asking Mr Spruce to try saying no, try saying no.

Instead of saying sorry, try saying no.

Instead of asking Mr Spruce to try saying sorry, try saying no.

Instead of answering Mr Spruce that "sorry", try saying no.

Test me with "z / z / z / yes".

Test more with "z / z / z / no".

297. Nameless ★★

By default, ASK SOMEONE ABOUT... applies only to a text token. We might want also to offer the player the option of asking characters about pieces of physical evidence. This example implements an ASK PERSON ABOUT THING command that is mostly synonymous with SHOW, with the added nuance that the player can ask about things that are not currently visible, as long as he has encountered them at some time in the past.

paste.png "Nameless"

The Black Chamber is a room. "Despite its menacing name, it is quite an ordinary room, underlying the post office above. Here letters are brought each day, unsealed, transcribed, resealed, and sent again on their way; their contents then analyzed and recorded."

The Nameless Advisor is a woman in the Black Chamber. "A woman whose name has never been disclosed to you sits at the window, writing numbers on a sheet of paper." The Advisor carries a sheet of paper. Understand "woman" as the nameless advisor.

The player carries a letter from the emperor. The description of the letter is "Though its origin is obvious, its meaning is secret: the letters are an inexplicable jumble."

Now we create our new action, "interrogating it about". We write the grammar lines so that we can show any object in sight to someone, but also ask someone about any object that we have ever interacted with in the game, whether it is currently visible or not.

A thing can be known or unknown. The Nameless Advisor is known.

Understand "ask [someone] about [any known thing]" as interrogating it about. interrogating it about is an action applying to two visible things.

Now we replace and redirect the showing action. This gets rid of the requirement in the default library that the player be holding anything he shows to another character:

Understand the commands "show" and "display" and "present" as something new.

Understand "show [something] to [someone]" or "display [something] to [someone]" or "present [something] to [someone]" as interrogating it about (with nouns reversed). Understand "show [someone] [something]" as interrogating it about.

This bit keeps track of what the player has seen, for the purposes of "any known thing":

Before printing the name of something (called the target): now the target is known.

Here we define what happens by default when we interrogate someone about something; we use the same response we get to asking someone about something that isn't otherwise interesting:

Carry out interrogating someone about something:
    say "There is no reply."

Now redirect all asking to a topic table, and all interrogating to an object table:

Instead of asking Nameless Advisor about a topic listed in the Table of Nameless Advisor Topics:
    say "[reply entry][paragraph break]".

Instead of interrogating Nameless Advisor about an item listed in the Table of Nameless Advisor Items:
    say "[reply entry][paragraph break]".

Table of Nameless Advisor Items

item

reply

letter

"'It is enciphered,' she remarks[if the advisor can see the letter], glancing over the contents[otherwise], after you have offered a detailed description[end if]. 'A substitution cipher of some complexity, I believe.'"

Advisor

"She listens to your inquiries about her identity and parentage with a placid smile, but does not answer."

Table of Nameless Advisor Topics

topic

reply

"cipher"

"'I know many dozens of ciphers,' she replies, smiling in a disquieting way."

"substitution cipher"

"'One letter is allowed to stand for another,' she explains, folding her hands together patiently. The backs of both hands are tattooed with silvery stars."

And just so that we can test what happens when asking someone about something out of sight:

The safe box is a container in the Chamber. It is fixed in place. It is openable and closed.

...and something unknown:

The poisonous apple is a thing.

Test me with "test sight / test knowledge".

Test sight with "i / x letter / ask Nameless Advisor about cipher / show cipher to Nameless Advisor / ask Nameless Advisor about the letter / show the letter to Nameless Advisor / show Nameless Advisor the letter".

Test knowledge with "open safe box / put letter in safe box / close safe box / ask Nameless Advisor about the letter / show the letter to Nameless Advisor / ask Nameless Advisor about the apple".

RB §7.8. Saying Complicated Things

As we saw in the overview, there are challenges in choosing the commands with which the player will communicate to the story. Two common approaches are ASK/TELL conversation, where the player can ask or tell characters about keywords, as in ASK JILL ABOUT JACK or TELL FARMER ABOUT CHICKEN COOP, and menu-based conversation, where the player is offered a list of things to say and must pick one (often by number), as in

1) Ask Jill where Jack went.
2) Tell Jill that the chicken coop was robbed.

or, sometimes,

1) "Jill, have you seen your no-good layabout brother Jack anywhere?"
2) "Look, Farmer Jill, I think a fox got into the chickens."

The problem with ASK/TELL conversation is that it can feel undirected - if the player doesn't know which keywords to ask or tell about next, he gets stuck. It also doesn't always provide much sense of ongoing context or conversational flow, since the player can ask lots of unrelated questions and jump around a lot. What's more, sometimes the thing the player character asks isn't quite the question the player had in mind. If we type ASK JILL ABOUT JACK, Jill could wind up answering any of a number of questions - where Jack is, how old Jack is, whether Jack committed the recent murder, and so on. The player doesn't have much fine control over the conversation. Nonetheless, this is sometimes just what we want: Farewell ★★ implements a moderately sophisticated system along these lines, which keeps track of what the player has already said and allows him to review past conversation.

Menu-based conversation solves most of these problems: a branching tree of conversation choices maintains a consistent flow of discussion, it's hard for the player to run out of things to say, and the player always knows what his character is about to say. But there are compensating flaws. For one thing, a menu doesn't allow for many surprises. The player can see all the conversation the story has to offer by working methodically through all the menu branches. (This problem is sometimes referred to as the "lawnmower effect", since the process of seeing all the conversation is like the process of running a lawnmower over every inch of the lawn. It becomes a chore rather than an entertainment.) Menu systems can be long-winded to set up and therefore none are exemplified here, but several have been released as extensions for Inform.

Since about 2001, more and more IF has used a sort of compromise method: the player is allowed to ask or tell about keywords, but he's sometimes given prompts about things to say that follow naturally on the conversation he was just having, as in

You could ask where Jack is.

Moreover, when he asks about a topic where many comments are possible, he'll be allowed to clarify, either using a menu or through a disambiguation question such as

>ask Jill about Jack
Do you want to ask where Jack is, how old Jack is, or whether Jack committed the recent murder?

Sweeney ★★ implements one such hybrid type of conversation.

A third option is to take away almost all the player's expressiveness and give him just one command, TALK TO. The player can TALK TO characters whenever he wants, and the story will pick the most appropriate thing for him to talk about. This works best in works with few or simple puzzles and a fast-moving, constrained plot, where the player will keep having new things to talk about. Cheese-makers ★★★ demonstrates this.

Finally, a few extreme games try to fake natural language understanding by looking for keywords in the player's input, rather than an exact grammar. This is perilous, because it is all too easy for the story to completely misunderstand what the player meant to type. Nonetheless, for the sake of example, see Complimentary Peanuts ★★★, in which the incomprehension is partly excused by the fact that the player is talking to someone a bit hard of hearing.

Examples

281. Farewell ★★

We begin with the idea that each person comes with his own table of things to say:

paste.png "Farewell"

A person has a table name called conversation.

Instead of asking someone about something:
    let the source be the conversation of the noun;
    if topic understood is a topic listed in source:
        if there is a turn stamp entry:
            say "[The noun] has already told you that [summary entry].";
        otherwise:
            now turn stamp entry is the turn count;
            say "[reply entry][paragraph break]";
    otherwise:
        say "[The noun] stares at you blankly."

For the sake of simplicity, we'll conflate asking and telling here, though it would certainly be possible to have a more complex implementation if we want the characters to be told things as well.

Instead of telling someone about something:
    try asking the noun about it.

Now we might want to add a recap command to review conversation that has already occurred.

Definition: a person is other if it is not the player.

Understand "recap" or "recall" or "review" as recalling conversations.

Recalling conversations is an action applying to nothing.

Since we've been recording the turn count of each conversation bit, we can even present these in order by sorting the tables first.

Carry out recalling conversations:
    repeat with speaker running through other people:
        let source be the conversation of the speaker;
        sort source in turn stamp order;
        say "[The speaker] has so far told you: [line break]";
        let index be 0;
        repeat through source:
            if there is a turn stamp entry:
                let index be 1;
                say " [summary entry][line break]";
        if index is 0, say " absolutely nothing[line break]";
        say conditional paragraph break.

Now it remains only to create a couple of characters and provide them both with something to say:

The Farewell Bend Cafe is a room. "Beautiful Farewell Bend, Idaho -- or is it Oregon? An almost-abandoned truckstop, in any case, on one of those interminable American east-west highways."

Tina is a woman in the Farewell Bend Cafe. The conversation of Tina is the Table of Tina's Chatter. "Tina the waitress is slowly pouring coffee from the pot with a black neck into the pot with an orange neck."

George is a man in the Farewell Bend Cafe. The conversation of George is the Table of George's Chatter. "There is also a large man at table five. The tattoo on his arm says George. For the moment we will assume that it is his own name and not someone else's."

Table of Tina's Chatter

topic

reply

summary

turn stamp

"aasvogel"

"'Oh, it's a vulture.'"

"that an aasvogel is a vulture"

a number

"acaudate"

"She shrugs, mid-pour. 'Means something doesn't have a tail.'"

"that acaudate means 'tailless'"

--

"absorptiometer"

"'It's a thing that measures the solubility of gases in a liquid,' she explains gently, as to a child."

"that an absorptiometer measures solubility of gasses in a liquid"

--

Table of George's Chatter

topic

reply

summary

turn stamp

"baccaceous"

"'Something that has or bears berries,' says George, without looking up."

"that baccaceous means berry-bearing or berry-like"

a number

"bagheera"

"'Oh, that'd be a velvet-like textile.'"

"that bagheera is a velvet-like textile"

--

"balistarius"

"'That's a crossbow-man,' George replies instantly."

"that a balistarius is a crossbow-man"

--

A word of warning: this system does assume that every person in the game has a conversation table defined. If that were not the case, we would have to be a bit more careful.

As always, we can override specific words, too:

Instead of asking Tina about "advertisement" for the first time:
    say "Tina looks embarrassed. 'Of course! I almost forgot.' She hands you a brochure.";
    move the brochure to the player.

The encyclopedia sales brochure is a thing. The description is "A glossy flyer indicating that you can receive a free Volume A-Aalto of the New Idahoan Encyclopedia Set if you send back the business reply card, and then have the option of purchasing the remaining volumes at a very very reasonable price."

Test me with "recap / ask tina about aasvogel / recap / ask george about baccaceous / ask tina about absorptiometer / recap / ask tina about advertisement / read brochure".

282. Sweeney ★★

paste.png "Sweeney"

A subject is a kind of thing. Some subjects are defined by the Table of Conversation Subjects.

Table of Conversation Subjects

subject

conversation

pies

Table of Pie Queries

employment

Table of Job Queries

Understand "job" as employment. Understand "meat" or "food" as pies.

Table of Job Queries

quip

discussion

label

subtopics

"whether there is a job available here"

"'Say, are you hiring?' you ask, as casually as you can manage. [The interlocutor] looks you over dubiously. 'I might be hiring someone, but I can't say it would necessarily be you.'"

0

--

"what happened to that boy that worked here"

"'Tell me, didn't you used to have a young assistant working here?' She shrugs. 'Young men these days are so unstable. He left-- who knows where he's gone? I haven't seen hair or fingernail of him for weeks.'"

0

--

with 3 blank rows.

Table of Pie Queries

quip

discussion

label

subtopics

"what pie fillings are available"

"'What pies do you have in today, Mrs Lovett?' you ask. She starts, then smiles. 'Meat pies, of course.'"

0

Table of Pie Flavor Queries

with 3 blank rows.

Table of Pie Flavor Queries

quip

discussion

label

subtopics

"what kind of meat"

"'What kind of meat goes into these pies, Mrs Lovett?' you ask pressingly. She looks shifty. 'Whatever the butcher brings this week,' she says. 'With the price of meat what it is, when you get it, you have to be glad of what you can get. If you get it.'"

0

--

To copy (first table - a table name) to (second table - a table name):
    repeat through first table:
        let copied quip be "blank";
        if there is a quip entry, now the copied quip is the quip entry;
        let copied discussion be "blank";
        if there is a discussion entry, now the copied discussion is the discussion entry;
        let copied subtopics be second table;
        if there is a subtopics entry, now the copied subtopics are the subtopics entry;
        choose a blank row in the second table;
        if copied quip is not "blank", now quip entry is copied quip;
        if copied discussion is not "blank", now discussion entry is copied discussion;
        if copied subtopics is not second table, now subtopics entry is copied subtopics.

Current conversation table is a table name that varies. Current conversation table is Table of Job Queries.

Interlocutor is a person that varies.

Understand "ask [someone] about [any subject]" as asking it about the subject.

Asking it about the subject is an action applying to two visible things.

Carry out asking it about the subject:
    say "You can't think of anything to say."

Instead of asking someone about the subject a subject listed in the Table of Conversation Subjects:
    now interlocutor is noun;
    now current conversation table is the conversation of the second noun;
    if the number of filled rows in the current conversation table is 1:
        repeat through current conversation table:
            now label entry is 1;
        now number understood is 1;
        try selecting 1 instead;
    if the number of filled rows in the current conversation table is 0:
        say "You can think of nothing further to say on that topic.";
        stop the action;
    otherwise:
        let index be 0;
        let total be the number of filled rows in the current conversation table;
        say "Do you mean ";
        repeat through current conversation table:
            now index is index + 1;
            now label entry is index;
            say "([index]) [quip entry]";
            if index is total, say "?";
            if index is total - 1, say ", or ";
            if index is less than total - 1, say ", ".

Understand "[number]" as selecting.

Selecting is an action applying to one number.

Carry out selecting:
    say "No such option is available."

Instead of selecting a label listed in the current conversation table:
    say "[discussion entry][paragraph break]";
    if there is a subtopics entry:
        copy subtopics entry to current conversation table;
    choose row with label of number understood in the current conversation table;
    blank out the whole row.

Mrs Lovett's Meat Pies is a room. Mrs Lovett is a woman in Meat Pies.

Test me with "ask lovett about pies / ask lovett about employment / 1 / 2 / ask lovett about pies".

168. Cheese-makers ★★★

As we have seen, there are a number of different ways of controlling conversation in interactive fiction, and the best choice of way will depend quite a lot on what kind of work we're writing.

One common model is to replace Inform's default ASK and TELL commands with a TALK TO command. This gives the player less control than he would otherwise have: instead of asking a character about any topic under the sun, he's restricted to seeing (or not seeing) a single sequence of text that the author has written in advance. On the other hand, such a system is harder for the player to break (since he can never ask about a topic that the author hasn't implemented), and easier for the author to tie into plot developments. If we give TALK TO different output at each scene, we get conversation that is always tied to the current state of the plot.

This is a design approach that works best in a game with a large number of short, focused scenes. For other kinds of conversation system design, compare the other examples listed in the Recipe Book.

paste.png "The Cheese-makers" by Phrynichus.

Chapter 1 - Replacing old talk commands and making a new one

Here, using some techniques that will be discussed in the chapter on Understanding, we get rid of Inform's default handling of ASK and TELL, and create our own TALK TO action instead:

Understand the commands "ask" and "tell" and "say" and "answer" as something new.

Understand "ask [text]" or "tell [text]" or "answer [text]" or "say [text]" as a mistake ("[talk to instead]").

Instead of asking someone to try doing something:
    say "[talk to instead][paragraph break]".

Instead of answering someone that something:
    say "[talk to instead][paragraph break]".

To say talk to instead:
    say "(To communicate in [story title], TALK TO a character.) "

Understand "talk to [someone]" as talking to. Understand "talk to [something]" as talking to. Talking to is an action applying to one visible thing.

Chapter 2 - Specific scenes and talking

Now, suppose we have a situation -- say, a stage play -- in which it is appropriate to talk to different characters at different times. During the prologue of the play, no one else is on-stage, and the player is to address the audience directly:

Section 1 - Prologue

When play begins:
    now right hand status line is "416 BC";
    now left hand status line is "[location]".

Prologue is a scene. Prologue begins when play begins.

The Theater of Dionysus is a room.

The audience is a person in the Theater. "The usual audience looks on: the priests and judges in the front row, and then Athenians, metics, and foreigners." The audience can be prepared or unprepared. The description is "Have you ever seen such a company of perjurers, pathics, and thieves?" Understand "priest" or "priests" or "priest of dionysus" or "judge" or "judges" or "athenians" or "metics" or "foreigners" as the audience.

Instead of talking to the player when the Prologue is happening:
    say "There will be plenty of occasion for muttered asides later in the play, but for now you must prepare the audience for things to come."

Instead of talking to the audience when the Prologue is happening:
    say "Drawing breath, you turn to the audience, and offer them a genial, witty, colorful, and of course crude synopsis of what they are about to see; describing all the characters in unmistakable terms and not omitting the most important of them all, your august self.";
    now the audience is prepared.

Instead of talking to the audience when the Prologue has happened:
    say "You may only direct monologues to the audience when the other actors are off-stage. Otherwise, their characters might have to notice."

Prologue ends when the audience is prepared.

But there might follow a scene in which the player shouldn't talk at all:

Section 2 - Parodos

Parodos is a scene. Parodos begins when Prologue ends.

When Parodos begins:
    move the chorus to the theater.

Instead of talking to someone during Parodos:
    say "Sssh: this moment belongs to the chorus. They've worked so hard on it, after all."

Parodos ends when the time since Parodos began is 4 minutes.

The chorus is a person. The description is "They are dressed in exaggerated rural costume and feminine masks, as they are meant to represent a company of female cheese-makers from the Spartan-occupied deme of Dekeleia." Understand "cheesewives" or "cheese-makers" or "chorus-leader" as the chorus.

Every turn during Parodos:
    repeat through Table of Choral Events:
        say "[output entry][paragraph break]";
        blank out the whole row;
        make no decision.

Table of Choral Events
output
"The chorus now begins its entry, accompanying with anapestic song its march up the eisodos."
"The chorus draws nearer, stomping and clomping and swinging their baskets of cheese."
"You stand aside as the chorus fills the orchestra and dances to and fro."
"The tune of the aulos-player grows more and more frenzied and then breaks off."

This last rule is a refinement borrowing from the Activities chapter, which gives characters different appearances in room descriptions depending on when we happen to look; because of the action of the play, we want to show the chorus and audience doing different things during different scenes.

Rule for writing a paragraph about the chorus during Parodos:
    say "The chorus are dancing and singing their way[if the time since Parodos began is less than 3 minutes] up the long walkways onto the stage[otherwise] into position in the orchestra[end if]. [The audience] appear to be pricing their costumes to the nearest obol: woe to the producer who cheats them of their due share of spectacle."

And now a scene in which the player can talk several times to a character (Heracles) but has no useful dialogue with the chorus, the audience, or himself. The prohibition from talking to the audience after the Prologue is already written, but we'll supply some appropriate responses for talking to the player or the chorus during this scene:

Section 3 - Episode

Episode is a scene. Episode begins when Parodos ends.

When Episode begins:
    move Heracles to the theater;
    say "The chorus falls silent, which is the cue: Heracles bursts out of the scene building."

Heracles is a man. The description is "Hard to mistake in his lion skin and boots, and carrying a formidable club." Heracles wears a lion skin and boots. He carries a formidable club. Heracles can be placid or annoyed. Heracles is placid. Heracles can be satisfied, intrigued, or unsatisfied. Heracles is unsatisfied.

Instead of talking to the chorus during Episode:
    say "Your improvised flirtation with the chorus raises no response but a crude gesture from the chorus-leader, who seems to be modeling the role on Iambe."

Instead of talking to the player during Episode:
    if Heracles is annoyed:
        say "You mutter to yourself about men with more appetite than brain. The actor playing Heracles ignores you, but it's good odds he's scowling under his mask. He hates it when anyone but himself ad-libs for attention.";
    otherwise:
        now Heracles is annoyed;
        say "'By the dog, he'll eat me if he gets a chance,' you mutter aside. [paragraph break]'What's that you say, my ignoble friend?' demands Heracles, hefting his club. He's not entirely joking: you've left the script just now."

Instead of talking to Heracles when Heracles is unsatisfied during Episode:
    say "'Dear Heracles, friendly Heracles,' you begin, cringing out of the way as he responds with one of his affectionate ox-killing punches to the shoulder. [paragraph break]But Heracles falls still, and looks almost thoughtful, as tell him you know how he may rout the Spartans, woo all twenty-four lactic ladies, and tame his savage gut with a bathtubful of porridge. [paragraph break]'Speak on, little man,' he says.";
    now Heracles is intrigued.

Instead of talking to Heracles when Heracles is intrigued during Episode:
    say "It takes several exchanges for him to wrap his one-inch brain around your ten-inch plan; but in the end he embraces the scheme, the women, and your humble self.";
    now Heracles is satisfied.

Every turn when not talking to someone during Episode:
    repeat through Table of Episodic Events:
        say "[output entry][paragraph break]";
        blank out the whole row;
        make no decision.

Table of Episodic Events
output
"With a fart and a roar, Heracles asks the world at large, and you in particular, where his dinner might be."
"In epic diction, Heracles invites the dairy-mistresses, whey-matrons, and concubines of curd to supply him a supper from their ample baskets."
"Heracles and the chorus banter about the proclivities of cheese-wives. The chorus suggest that Heracles, as a son of Zeus, must know something about the appetites of which they speak."
"Heracles boasts that a man like himself can perform any feat, but only when his belly is full. Coyly, the matrons prance and dance, skip and gambol out of his grasp, singing mockingly about heads of garlic and loaves of sesame-crusted bread."
"The song of the feta fanciers now turns to pots of honey and new-made wine, borrowing verses from last year's Lenaia winner, 'The Bees'. With a jolt, you realize that you've missed your cue and the chorus are filling in for you."
"Playing for time, the chorus-leader elaborates a whole banquet: rabbit stew, shanks of lamb, spitted quails, eels from lake Copais. Heracles looks as near swooning as any girl fresh from Brauron."
"The chorus-leader extends the list of delicacies to include ox-brains, ham-hocks, barley, mullet, carrots, pigeons, lentils, radishes, peas, and apples both wine-dark and golden. The audience shifts on the benches. An expression of gloom settles over the Priest of Dionysus in the front row."
"Inspired by Euripides['] own Muse, the chorus-leader invents a mock-Alcaean hymn on the merits of chervil. This is clearly his swan-song: if you don't speak at last, the play will come to a halt."
"Silence descends."

Rule for writing a paragraph about Heracles during Episode:
    say "[Heracles] stands at the center of the orchestra, with members of [the chorus] ranged on either side. [paragraph break][The audience] appear to be reserving their judgement, though they show signs of restiveness at the usual jokes: must there be a Heracles in [italic type]every[roman type] play?"

Episode ends successfully when Heracles is satisfied.

When Episode ends successfully:
    say "That, of course, is your cue: you're to come back on as Pan thirty verses from now, and it takes time to put on the hooves and the woolly-legged trousers.";
    end the story saying "You exit".

Episode ends disastrously when the number of filled rows in the Table of Episodic Events is 0.

When Episode ends disastrously:
    end the story saying "The production has crashed to a halt".

Test me with "ask audience about me / tell audience about me / audience, hello / audience, jump / talk to me / talk to audience / g / talk to chorus / look / x heracles / talk to me / talk to audience / z / look / talk to heracles / g".

376. Complimentary Peanuts ★★★

The "reading a command" activity is not the only point at which we can interact with snippets, as it happens; it is merely the most useful. "The player's command" can be consulted at other points, however, as in this example of your somewhat deaf (or distracted, or simply cussed) Aunt:

paste.png "Complimentary Peanuts"

Instead of asking Aunt Martha to try doing something:
    repeat through Table of Aunt Martha's Commentary:
        if player's command includes topic entry:
            say "[commentary entry][paragraph break]";
            rule succeeds;
    say "'Hmmf,' says Aunt Martha."

The topic understood is also a snippet, so that whenever one has been generated, we can treat it in the same way as "the player's command":

Asking someone about something is speech.
Telling someone about something is speech.
Answering someone that something is speech.
Asking someone for something is speech.

Instead of speech when the noun is Aunt Martha:
    repeat through Table of Aunt Martha's commentary:
        if the topic understood includes topic entry:
            say "[commentary entry][paragraph break]";
            rule succeeds;
    say "'Hmmf,' says Aunt Martha."

This is superior to checking "the player's command" because we do not want ASK MARTHA ABOUT FRENCH FRIES to trigger the "Martha" keyword, only the "french fries" keywords.

The Empyrean Shuttle Bay is a room. "From here you have an excellent view of the colony world, which looks... well, it looks discouragingly orange. But terraforming is in progress."

Aunt Martha is a woman in the Empyrean Shuttle Bay. A gleaming shuttle and a stack of rations are in the Shuttle Bay. The shuttle is a vehicle. "Your shuttle awaits."

Table of Aunt Martha's Commentary

topic

commentary

"shuttle"

"'Shuttles! I hate shuttles,' Aunt Martha grumbles. 'Give me an airplane! AIRPLANE.'"

"airplane/airport"

"'Those were the days,' Aunt Martha agrees, plainly reliving the days when she wore a blue-and-white uniform and passed out packets of salted pretzels."

"rations"

"'Do you think there are any peanuts in there?' she asks in a wistful tone."

Test me with "martha, get in the shuttle / martha, for pity's sake, do you see an airplane around here? / martha, pass me the rations".

This means that Martha will respond to keywords regardless of the setting in which they occur. For instance:

>martha, get in the shuttle
"Shuttles! I hate shuttles," Aunt Martha grumbles. "Give me an airplane! AIRPLANE."

>martha, for pity's sake, do you see an airplane around here?
"Those were the days," Aunt Martha agrees, plainly reliving the days when she wore a blue-and-white uniform and passed out packets of salted peanuts.

>martha, pass me the rations
"Do you think there are any peanuts in there?" she asks in a wistful tone.

This is not the stuff of which Loebner-winning chatbots are made, admittedly, but it is occasionally a useful alternative to stricter modes of command-parsing.

RB §7.9. The Flow of Conversation

All this discussion of conversation commands and ways to model dialogue doesn't address the higher-level design issue: how do we approach writing this material so that it has a rhythm and flow? How do we know when we've created enough conversation? How can we avoid sounding hopelessly stilted when the nature of IF implementation requires us to break our text into small snippets?

While most authors develop their own approaches, there is some general advice that may help, especially for works that have a strong narrative progression.

It helps to have the plot of the story, with all its component scenes, planned in advance. That doesn't mean there can't be any changes later, but having a list of the different scenes can help us remember the different contexts in which information can appear. If we're using Inform's scenes feature, we may even want to restrict some dialogue to be available only during a given scene.

The next step is to go through scene by scene and create the "spine" of the scene. What must be said during this section? Is there anything the player can't leave without knowing? If the player isn't moving the scene forward fast enough, will the other character or characters volunteer information in order to keep the pace going?

It often helps to draft a transcript showing what we imagine as the ideal playthrough of the scene - writing straight through can create a natural flow of dialogue - before dividing the dialogue into pieces for implementation.

Once the scene is complete enough for the player to get through from beginning to end, we can start filling it out. At this point, it sometimes helps to play through the scene a number of times and add new dialogue elements as we think of things that our character might reasonably want to say. Sometimes these additions will turn out to be short tangents from the main flow of a very directed scene; sometimes they might be important branches that lead the scene to an entirely alternate outcome. The main thing is to make sure that, if the scene needs to hit certain points before ending, none of our branches keep the player from returning to the subject at hand.

RB §7.10. Character Emotion

In a complex story, characters may evolve strong feelings about the player. Often we want to hint at the character's feelings through gesture and tone of voice - little things woven into dialogue and action sequences that might otherwise be unchanged. Ferragamo Again ★★ demonstrates creating phrases to give all our characters different ways to express their irritation at the player.

Then again, sometimes a discussion might produce quite spectacular results if a character is in the wrong mood. Being Peter shows the bare bones of an implementation in which a character's attitude rulebook is consulted to determine what her response will be - allowing for arbitrarily complicated outcomes.

Examples

405. Being Peter

Let's say that we're implementing a particularly irrational and volatile character. Some of the time she remains composed; some of the time she reacts with unexpected vehemence for reasons only partly related to what was said.

Moreover, her responses are divided between successful and failing outcomes, where success indicates that she's not too upset and failure means that she is distraught; we use this to determine how the rest of the room reacts.

paste.png "Being Peter"

The Drawing Room is a room. "The company is assembled here for champagne. Most of it, anyway: Mary is on the phone to her babysitter, Roger is keeping her anxious company, and Carol doesn't drink. But everyone else."

Maggie is a woman in the Drawing Room.

The player wears a top hat.

Quizzing it about is an action applying to one thing and one visible thing. Understand "ask [someone] about [any thing]" as quizzing it about.

Instead of quizzing Maggie about something:
    follow the attitude rules;
    say "Everyone waits to see what the reaction will be: [outcome of the rulebook].";
    if rule succeeded, say "There is general relief.";
    otherwise say "Everyone is pointedly silent."

The attitude rules are a rulebook. The attitude rules have outcomes she stays calm (no outcome - default), she gets angry (failure), she has a stroke (failure), she is only mildly annoyed (success), and she is elated (success).

Here we want Inform to consult every appropriate attitude rule until it gets to some answer; if an attitude rule does not provide a result, the default 'no outcome' will mean that we go on to the next rule, and so on.

A subject is a kind of thing. income, love life, and children are subjects.

An attitude rule for quizzing Maggie about love life:
    she gets angry.

An attitude rule:
    if the player wears the top hat, she gets angry.

Now, as we saw, the 'no outcome' result will never be returned and printed as Maggie's reaction, precisely because it is "no outcome". Therefore, we provide a final attitude rule which will give her a default response to all statements:

The last attitude rule:
    she is only mildly annoyed.

Test me with "ask maggie about love / ask maggie about income / take off hat / ask maggie about income".

There are plenty of contexts where we might want named outcomes for clarity but not want to print the results literally afterward.

170. Ferragamo Again ★★

Here we use phrases that match individual items where possible, and the general kind otherwise:

paste.png "Ferragamo Again"

The Break Room is a room. Vanessa, Tina, and Lisa are women in the Break Room. Mark and Holman are men in the Break Room.

Understand the commands "ask" and "tell" and "answer" as something new.

Understand "talk about [any subject]" as talking about. Talking about is an action applying to one visible thing.

Understand "talk about [text]" as talking randomly about. Talking randomly about is an action applying to one topic. Carry out talking randomly about: say "Mostly you're interested in [the list of subjects]."

Carry out talking about something:
    now the previous subject is the noun.

Report talking about something:
    say "You chat for a while about [the noun]."

A subject is a kind of thing. Assyrian vowel sounds, designer handbags, and instant run-off voting are subjects. Understand "linguistics" and "mute" and "stop" as sounds. Understand "prada" and "tods" and "coach" and "carmen marc valvo" as designer handbags. Understand "reform" and "election" and "election fraud" and "two-party system" and "Diebold" as instant run-off voting.

To say (annoyed-person - a person) gestures in irritation:
    say "[The annoyed-person] sighs heavily. [run paragraph on]"

To say (annoyed-person - Vanessa) gestures in irritation:
    say "[The annoyed-person] takes off her glasses and polishes them on her sleeve. [run paragraph on]".

To say (annoyed-person - Holman) gestures in irritation:
    say "Holman bobs his head. [run paragraph on]"

The previous subject is a subject that varies.

Instead of talking about something for more than one turn:
    if the noun is the previous subject, say "[a random visible person who is not the player gestures in irritation]Maybe you should let this one go.[line break][paragraph break]";
    otherwise continue the action.

Test me with "talk about chocolate / talk about vowel sounds / g / talk about handbags / talk about prada / talk about tods".

RB §7.11. Character Knowledge and Reasoning

A character may be endowed with knowledge and even reasoning skills. Relations form quite a good way of keeping track of such problems: for instance, we can allow characters to be acquainted with one another with a relation such as

Lucy knows Lady Cardew.

Or we might keep track of more complicated attitudes between characters, as in Murder on the Orient Express ★★, in which some characters suspect others of the crime.

Alternatively, we might have a list of salient facts that are important in our story. We might declare these as values, and then characters could know, learn, and forget entries as appropriate:

A fact is a kind of value. Some facts are defined by the Table of All Known Facts.

Knowledge relates various people to various facts. The verb to know (he knows, they know, he knew, it is known) implies the knowledge relation.

Table of All Known Facts
fact summary
shoe-size "Lucy wears a size 9 shoe."
sunset-time "Sunset is at 8:22 PM this evening."

Lucy knows shoe-size.
Bob knows sunset-time and shoe-size.

Or again we might keep a whole database of information in a table: the characters in Questionable Revolutions ★★★ know dates, countries, and a short description for each of several rebellions and popular uprisings, while in Queen of Sheba ★★★, Solomon is able to answer who, what, where, when, and why questions about a range of topics. This kind of approach is most useful when the characters need to display a deep knowledge of a particular field. The facts stored in the Table of All Known Facts, above, are comparatively sparse, because there we are designing a story in which not all data about the world is equally valuable: Lucy doesn't know the shoe size of every person in the story, because for some reason it is only her own shoe size that matters. On the other hand, the Table of All Known Facts can store different kinds of information, whereas the revolutions table has no way of storing shoe sizes or sunset times. And Murder on the Orient Express ★★ works differently again, because it is storing knowledge that concerns people and things that already exist in the world model, rather than abstract ideas. Our way of modeling character knowledge, in other words, will depend quite a lot on what kind of knowledge it is.

The possibilities of character reasoning are similarly broad, but The Problem of Edith ★★★ introduces one kind: the character has a concept of how different conversation topics relate to one another, so that when she is asked about a new keyword, she picks a response that makes the question most relevant to the conversation already in progress.

We end with a longer scenario, in which we track what the character knows about the player and the conversational state: in Chronic Hinting Syndrome ★★★★, the main character guides conversation in the direction he intends it to go, with the player's sometimes-reluctant participation.

See also

Obedient Characters for a character who needs to be taught how to perform actions before doing them
Characters Following a Script for a programmable robot who can be given whole sequences of actions to perform

Examples

242. Murder on the Orient Express ★★

The following example creates two new relations, and two new verbs, in order to set up a tangled web of intrigue.

paste.png "Murder on the Orient Express"

The Dining Car is a room. Lord Peter is a man in the Dining Car. Sherlock Holmes is a man in the Dining Car. Miss Marple is a woman in the Dining Car. Adam Dalgliesh is a man in the Dining Car.

Suspecting relates various people to one person.

The verb to suspect means the suspecting relation.

Dalgliesh suspects Holmes. Holmes suspects Lord Peter. Lord Peter suspects Holmes. Miss Marple suspects the player.

Exculpating relates one thing to various people.

The verb to exculpate means the exculpating relation.

The silver bullet exculpates the player. The pipe ash exculpates Holmes. The poison pen letter exculpates Lord Peter. The poison pen letter exculpates Miss Marple. [Poor Dalgliesh. I guess he did it.]

The pipe ash, the letter and the silver bullet are carried.

Given this, we can then set up elaborate rules:

Instead of showing something to a person who suspects the player:
    say "'You would say that,' remarks [the second noun] darkly.".

Instead of showing something which exculpates the player to someone:
    say "'How striking!' says [the second noun]. 'Almost I begin to distrust myself.'".

Test me with "show the letter to miss marple / show the silver bullet to holmes".

And so on: "if Dalgliesh suspects someone who is exculpated by something carried by the player...", for instance, makes a fitting final example for this chapter. The description

someone who is exculpated by something carried by the player

expresses a complicated idea in very few words, and in such a way that a passer-by looking at the source text would immediately see what was meant.

The moral is that relations allow sophisticated patterns of behaviour to be created in a way that reads back naturally as English.

235. The Problem of Edith ★★★

Suppose that we have a core set of issues we want to be able to bring up with all the characters, and we want characters to draw intelligent connections between different conversation topics. We will need some model of how things relate to one another, so:

paste.png "The Problem of Edith"

Suggestion relates things to each other. The verb to suggest means the suggestion relation.

A subject is a kind of thing. The current subject is a thing that varies. greeting is a subject.

Understand "ask [someone] about [any subject]" as asking it about the subject. Understand "tell [someone] about [any subject]" as asking it about the subject.

Asking it about the subject is an action applying to one thing and one visible thing.

Carry out asking it about the subject:
    say "'Hmm, [the second noun],' says [the noun]. ";
    relate the current subject with the second noun;
    now the current subject is the second noun.

And if we wanted to offer the player some hints about angles he could pursue:

Instead of thinking:
    say "You contemplate [a list of things suggested by the current subject]."

For that matter, we could use the same system to have characters make sense of any physical evidence the character shows them:

Instead of showing something which suggests the current subject to someone:
    say "[The second noun] nods impatiently."

Instead of showing something to someone:
    let the next subject be the next step via the suggestion relation from the noun to the current subject;
    if the next subject is a subject:
        try asking the second noun about the subject the next subject;
    otherwise:
        say "[The second noun] shrugs."

When play begins:
    now the left hand status line is "Discussing: [current subject]";
    now the right hand status line is " ".

Broughton Hall is a room. Lady Uckfield is a woman in Broughton Hall. "Lady Uckfield sits at her desk, looking wholly composed."

The nasty letter is a thing carried by the player. The nasty letter suggests infidelity and penmanship. The ten-pound note is carried by the player. It suggests money.

Infidelity is a subject. Infidelity suggests marriage and divorce. Marriage suggests love. Marriage, love, and divorce are subjects.

Penmanship is a subject. Penmanship suggests education. Education is a subject. Class status and money are subjects. Class status suggests education. Money suggests class status and marriage.

The current subject is divorce.

Now we can define what gets said when the subject is changed, regardless of whether the segue was introduced in speech or by a shown object. Since rows are blanked after use, the speaker will never repeat herself; if we provide more than one line about the same pair of topics, the first one will be used, then the second, and so on, until the table runs out:

To relate (initial - a subject) with (next - a subject):
    repeat through Table of Remarks:
        if the initial is starting entry and the next is the final entry:
            say "[comment entry][paragraph break]";
            blank out the whole row;
            rule succeeds;
    say paragraph break.

Table of Remarks

starting

final

comment

divorce

love

"'As it seems to me, all the love is on one side,' she says crisply. 'And that rarely works.'"

divorce

love

"'Stop making that plea: it won't work.'"

divorce

infidelity

"'Frankly, I rather think there would have been cause enough for divorce without the perversely plentiful evidence of unfaithfulness.'"

divorce

money

"'If you mean that the divorce will be expensive, I know it,' she says. 'But I can think of no happier investment.'"

marriage

money

"'If you wish me to understand that it was a marriage for money, you could have spared your energy. That was patent from the outset.'"

infidelity

money

"'I'm sorry, but I don't see how having married for money excuses a subsequent infidelity.'"

If we had more than one character in the scenario, we could provide multiple tables, but this will do to demonstrate the idea.

Of course, we can override specific instances, if we want the character always to say the same thing regardless of how we came to this point:

Instead of asking Lady Uckfield about the subject penmanship:
    now the current subject is penmanship;
    say "She sighs. 'So few people write really beautifully these days.'"

Test me with "think / ask lady about infidelity / show nasty letter to lady / show note to lady / think / ask lady about divorce / ask lady about love / ask lady about marriage / ask lady about divorce / ask lady about love / ask lady about penmanship".

We would have to be careful about this system, since we have applied a various-to-various relation to every single object in the game. In practice it would probably be wisest to restrict it a bit, with judicious definitions of kind and so on.

278. Questionable Revolutions ★★★

paste.png "Questionable Revolutions"

Interrogative is a kind of value. The interrogatives are who, what, when, where, how, and why.

Current question is an interrogative that varies.

After asking someone about something: respond to the question. After answering someone that something: respond to the question.

After telling someone about something: say "You're here to ask questions."

Country is a kind of value. The countries are Czechoslovakia, Georgia, Sweden, Italy, Spain.

Table of Information

topic

date

place

definition

"velvet revolution"

1989

Czechoslovakia

"A bloodless revolution in Czechoslovakia, in which popular protests led to the resignation of the communist president Gustav Husak, and the election of Vaclav Havel in his place."

"rose revolution"

2003

Georgia

"A revolution in which President Eduard Shevardnadze was interrupted by protesters in the middle of his speech, and forced to flee."

"spanish revolution"

1936

Spain

"An anarchist and socialist movement during the Spanish civil war."

After reading a command:
    if the player's command includes "[interrogative]", now the current question is the interrogative understood.

To respond to the question:
    repeat through the Table of Information:
        if the topic understood includes topic entry:
            if the current question is what or the current question is who, say definition entry appropriately;
            if the current question is when, say date entry appropriately;
            if the current question is where, say place entry appropriately;
            rule succeeds;
    say "[The noun] shrugs."

Understand "ask [someone] [text]" as asking it about.

Comprehension is a kind of value. The comprehensions are vague, erroneous, and correct.

Table of Understanding

character

years

geography

general comprehension

Dr Tweedy

correct

correct

correct

Ms Finch

erroneous

erroneous

correct

Ms Clarion

vague

vague

erroneous

When play begins:
    say "Here you are in the first class cabin, but no matter how fancy the seats are, you can still get bored circling over Zurich for three hours on end. To kill time, you and the other passengers are playing a trivia game, and the final topic is your specialty: revolutions."

First Class Cabin is a room. Dr Tweedy is a man in First Class. Ms Finch and Ms Clarion are women in First Class.

To say (year - a number) appropriately:
    choose row with character of the noun in the Table of Understanding;
    if years entry is correct:
        say "'[year],' replies [the noun] promptly.";
        increment the quiz score of the noun;
    if years entry is erroneous:
        let guess be a random number between 1900 and 2005;
        say "'[guess]?' guesses [the noun], with an air of diffidence[if guess is the year]. Which is right, as it happens[end if].";
        if guess is the year, increment the quiz score of the noun;
    if years entry is vague:
        let offset be a random number between -5 and 5;
        let year be year + offset;
        say "'I think [year]. About then. Close, anyway,' replies [the noun][if the offset is 0], getting it right[end if].";
        if offset is 0, increment the quiz score of the noun.

To say (spot - a country) appropriately:
    choose row with character of the noun in the Table of Understanding;
    if geography entry is correct:
        say "'[spot],' replies [the noun] promptly.";
        increment the quiz score of the noun;
    if geography entry is erroneous:
        let guess be a random country;
        say "'Er... [guess]?' says [the noun][if guess is the spot]. Which is of course correct[end if].";
        if guess is the spot, increment the quiz score of the noun;
    if geography entry is vague, say "'Europe,' replies [the noun] with confidence."

To say (explanation - some text) appropriately:
    choose row with character of the noun in the Table of Understanding;
    if general comprehension entry is correct:
        say "'[explanation]'[paragraph break]";
        increment the quiz score of the noun;
    otherwise:
        choose a random row in the Table of Information;
        say "'[definition entry]'[paragraph break]";
        if the definition entry is explanation:
            say "[A random other person who is not the noun] looks surprised that this came out right.";
            increment the quiz score of the noun.

A person has a number called quiz score. The quiz score of Tweedy is 48. The quiz score of Finch is 2. The quiz score of Clarion is 4.

Definition: a person is other if it is not the player.

When play begins:
    now left hand status line is "T: [quiz score of Tweedy] F: [quiz score of Finch] C: [quiz score of Clarion]";
    now right hand status line is "[time of day]".

Test me with "dr tweedy, where was the velvet revolution located / ms finch, when was the rose revolution / ms finch, what was the rose revolution / ms clarion, when was the spanish revolution / g / g / ms finch, when was the spanish revolution".

We have so far seen several ways to write conversational characters in Inform, and we will see more before the end of the manual. This naturally raises the question, which should we use? To which the answer is: it depends on the sort of game we're writing, and what we want our characters to do. The more rich and complex the system, the more likely that it will require a lot of content; if we add question types as well as keywords, for instance, we instantly multiply the number of responses we have to write by five or six. It is not worth doing this unless there is some corresponding advantage within the game.

279. The Queen of Sheba ★★★

Suppose we want the player to ask questions of slightly more complexity - we might want to build in a system that understood "who", "what", "where", and "when", for instance. We could use a topic table for this, too:

paste.png "The Queen of Sheba"

Interrogative is a kind of value. The interrogatives are who, what, when, where, how, and why.

Current question is an interrogative that varies.

After asking someone about something: respond to the question. After answering someone that something: respond to the question.

After telling someone about something: say "You're here to ask questions and test Solomon's wisdom, not to give him a sample of your own."

Table of Wise Answers

topic

question type

reply

"rain/weather/clouds/cloud/rains"

what

"'Clouds are a disturbance made by the paths of birds,' Solomon replies. 'The air beaten by their wings becomes agitated, as when a river is stirred and the mud churns up.'"

"rain/weather/clouds/cloud/rains"

where

"'Weather is contained in a great silk bag which holds in the heavens,' replies Solomon."

"hunger/food/eating"

when

"'Sorry, are you getting hungry?' he says, and rings a bell to summon servants."

"hunger/food/eating"

why

"'Men were made to need food in order that they must farm and cook and dine together,' Solomon replies. 'Otherwise, they might live apart, each sufficient in himself. But no man can feed himself alone all through his life.'"

"Solomon/he/himself"

who

"'As you see,' he says, holding out his arms to each side."

"Solomon/he/himself"

what

"'I am an ordinary man,' he answers."

One of the nice things about this system is that it only resets the "current question" when we get a new question word. For instance, this test will produce different replies to the question about Solomon himself, because the second time he is still in the mode of answering "what" questions:

Test me with "ask solomon about himself / ask solomon what rain is / ask solomon about himself".

If Solomon is to live up to his reputation at all, his wisdom table will have to be quite a bit longer - though one also would want to be careful, because forcing the game to cycle through a really immense table could be quite time-consuming. In fact, for the sake of this example, let's reward the player for managing to stay within the (narrow) range of Solomon's knowledge:

The Hall of Almug Tree Pillars is a room. "The pillars of the room are made of almug tree, the ceiling made of silk and the floor of glass." Solomon is a man in the Hall of Almug Tree Pillars. Solomon has a number called wisdom. The wisdom of Solomon is 0.

Every turn:
    if the wisdom of Solomon is 3:
        say "Truly, Solomon has answered all your questions, and his wisdom is even as great as you had heard!";
        end the story saying "Your heart beats strangely fast".

When play begins, say "'Oh, you've arrived,' says Solomon."

In a real game we'd need to be a great deal subtler. All the same, if we have a character of quite limited resources to present to the player, it's a good idea to give the player some incentive to stay on topic, ask questions the character can answer, and generally interact within the parameters we're prepared for.

Now, this last bit requires some trickery from later chapters, particularly those on Understanding and Activities, to pull the question words out of the player's command:

After reading a command:
    if the player's command includes "[interrogative]", now the current question is the interrogative understood.

To respond to the question:
    repeat through the Table of Wise Answers:
        if the topic understood includes topic entry:
            if the current question is the question type entry:
                say "[reply entry][paragraph break]";
                increment the wisdom of Solomon;
                rule succeeds;
    say "Solomon looks blank, appalled by a question for which he was not prepared.";
    end the story saying "You have befuddled Solomon!"

Understand "ask [someone] [text]" as asking it about.

And now we have a game that will accept (though not always respond very sensibly to) questions of almost any form we might put to another character: ASK SOLOMON WHAT RAIN IS will be answered, but then again, it won't be distinguished from, say, ASK SOLOMON WHETHER THIS PERSISTENT RAIN IS A DIVINE PUNISHMENT OR WHAT.

All the same, a system that allowed the player a bit more specification of questions than simple keyword-use might be useful in a mystery game, for instance, where we might want to let our detective conduct inquiries into specific details. An alternative approach to the rather free one above would be to force the player to use only questions of the form WHAT IS RAIN? or WHO ARE YOU?: this would cut down on false-positive matches. But we might still choose to store the responses in a table of this type.

341. Chronic Hinting Syndrome ★★★★

Suppose we have a conversation system in which it is important to keep track of which subjects the player has heard mentioned. If we're careful to mark subjects in brackets, we can use the "printing the name of" activity to record which things have been mentioned so far:

paste.png "Chronic Hinting Syndrome"

A subject is a kind of thing.

Knowledge relates various people to various subjects. The verb to know means the knowledge relation.

Awareness relates various people to various subjects. The verb to be aware of means the awareness relation.

Definition: a subject is pending if the player is aware of it and it is not known by the player.

Instead of thinking:
    if the number of pending subjects is 0, say "You have no fresh leads at the moment.";
    otherwise say "You recall that thus far you have not followed up with questions about [the list of pending subjects]."

After printing the name of a subject (called idea):
    now the player is aware of the idea.

Now suppose that as an added convenience for the player, we let him turn on a mode in which useful conversation topics are always automatically highlighted in the text, so he doesn't waste his time trying to follow up dead leads:

Setting is a kind of value. The settings are bright and dull. Understand "on" as bright. Understand "off" as dull.

Highlighting is a setting that varies. Highlighting is dull.

Understand "highlighting [setting]" as setting highlighting. Setting highlighting is an action out of world, applying to one setting.

Carry out setting highlighting:
    now highlighting is the setting understood.

Report setting highlighting:
    say "Highlighting is now [if highlighting is dull]off[otherwise]on[end if]."

Before printing the name of a subject (called idea) when highlighting is bright:
    unless the player knows the idea:
        say "[bold type]".

After printing the name of a subject when highlighting is bright:
    say "[roman type]".

...And the rest is peripheral.

The Sickbay is a room. "A place arranged for Nathan's comfort, since his sickness has been prolonged and because he becomes so irritating when not comfortable." The Hallway is outside from the Sickbay.

A supporter can be untried or rejected. A supporter is usually untried.

The Sickbay contains a wobbly pedestal, a table, and a sickbed. Understand "bed" as the sickbed. The pedestal, the table, and the sickbed are supporters. Nathan is a man on the sickbed. The sickbed is scenery. The initial appearance of the wobbly pedestal is "A wobbly pedestal near the door has sometimes been known to support vases of flowers, but is currently bare." The initial appearance of the table is "There is also a table of a more ordinary sort."

Nathan can be active or passive.

After printing the name of Nathan: now Nathan is passive.

Instead of putting the sculpture on the table:
    now the table is rejected;
    say "'[Not there],' [Nathan] snaps. 'The table is way too far from the sickbed.'"

Instead of putting the sculpture on the sickbed:
    now the sickbed is rejected;
    say "'[Not there],' [Nathan] rebukes you. 'You don't want me knocking it over if I roll around. In pain.'"

Instead of putting the sculpture on the pedestal:
    now the pedestal is rejected;
    say "The pedestal starts to wobble so ominously that you don't dare let go.

'[Not there],' says [Nathan]. 'That thing is falling apart.'"

Before putting something on the down: try dropping the noun instead.

To say not there:
    if all the supporters are rejected:
        say "Look, the floor would be fine";
    otherwise if the number of rejected supporters is 1:
        say "Yeah, anywhere but there, I'm afraid";
    otherwise:
        say "Come on, use your head -- I can't be watching you all the time, I'm sick".

Instead of going outside when the player is carrying the sculpture:
    say "You've still got this sculpture to get rid of."

Instead of going outside when the breakage is pending:
    say "You can't very well smash in front of [Nathan] his prize sculpture and then just scamper off without saying something. Appealing though the thought is at the moment."

Instead of going outside when a subject which is not the breakage is pending:
    say "'Yeah, go ahead,' says [Nathan], with a martyr-like air. 'It's probably best that you don't hear about [the random pending subject]. It's not something I'd go into normally.'"

The breakage is a subject. The description is "It's not a big deal. I'll just buy a new [mental wave generator].' A slight awkward pause. 'I mean, this one was a [gift], but don't worry about it". Understand "accident" or "smashing" or "breaking" or "shard" or "mishap" or "shards" or "mistake" as the breakage. Understand "sculpture" as the breakage when the player is not carrying the sculpture.

Instead of saying sorry in the presence of Nathan when the player is aware of the breakage:
    try asking Nathan about the matter of breakage.

Instead of asking Nathan to try saying sorry when the player is aware of the breakage:
    try asking Nathan about the matter of breakage.

The mental wave generator is a subject. The description is "They're kind of expensive but I can save up. I really need one, though, because of my [dreams]".

The dreams is a subject. The description is "They're not the kind of dream you want to have.' He closes his eyes and contemplates these undesirable dreams. 'Have you ever woken up convinced you were dead? No, probably not. Well... At any rate, I need the [generator]. Oh, don't worry, they're expensive but not so expensive that I won't be able to save up for another, in a few months".

The gift is a subject. The description is "[The mental wave generator] was a present from a girl named [Shari]. Actually I'm not sure she'd take to being called a girl".

Shari is a subject. The description is "Look, let's just not go into it, okay? I don't really want to relive all that right now. I still have a six-inch [scar] shaped like a banana in the middle of my back".

The scar is a subject.

Instead of asking Nathan about the matter of the scar:
    say "Nathan clears his throat, lowers his voice, and begins to tell you the story...";
    end the story saying "End of Demo -- Register to Continue!!"

Understand "ask [someone] about [any subject]" as asking it about the matter of.

Asking it about the matter of is an action applying to one thing and one visible thing.

Check asking it about the matter of:
    if the player is not aware of the second noun, say "What [second noun]?" instead;
    if the noun does not know the second noun, say "'I've no idea,' replies [the noun]." instead;
    if the player knows the second noun, say "You've already covered that. The response was '[description of the second noun].'" instead.

Carry out asking it about the matter of:
    now the player knows the second noun.

Report asking it about the matter of:
    say "'[description of the second noun],' says [the noun]."

Instead of telling Nathan about something:
    say "He pinches the bridge of his nose. 'I can't really follow this right now,' he says. 'I'm sorry.'"

Instead of asking Nathan about something:
    say "He shrugs weakly."

When play begins:
    say "'Just put that down anywhere,' says [Nathan], as you come into the room. He's sitting in the sickbed with his legs straight out in front of him. 'I don't care where.' His voice is weak, but it sharpens up for the last remark: 'And don't make a lot of noise about it.'

Considering that he woke you from a sound slumber to beg you to bring this thing over, his attitude is a bit much. You stare dubiously at the awkward crystal sculpture in your hands.";
    now Nathan knows every subject.

Instead of asking Nathan about something while the player carries the sculpture, say "[Nathan] moans dramatically and refuses to be drawn into conversation."

The player is carrying an awkward crystal sculpture. Understand "objet" or "objet de hideous" as the sculpture. The description of the sculpture is "It might possibly be natural, or it might be man-made. It might appeal to someone, but it is certainly not to your tastes."

Instead of showing the sculpture to Nathan:
    say "'Please put it anywhere,' he says."

Instead of giving the sculpture to Nathan:
    say "'No, it doesn't work if I touch it. That's why I couldn't-- well, just put it down.'"

After dropping the sculpture:
    now the player is aware of the breakage;
    now the sculpture is nowhere;
    say "You are incredibly careful, but somehow the sculpture slips -- you might almost say slithers -- from your fingers and crashes into a thousand shards at the feet of [Nathan].

There is a tense silence."

Before reading a command: now Nathan is active.

Every turn while not asking:
    if Nathan is passive, rule succeeds;
    if the player is carrying the sculpture:
        if showing or giving, rule succeeds;
        say "[Nathan] opens one eye and stares at you meaningfully. He is waiting for you to deposit his objet de hideous somewhere.";
        rule succeeds;
    if the breakage is pending:
        if dropping, rule succeeds;
        say "You're not quite sure where to begin, but you can't very well leave without making at least some remark on the smashing of the sculpture.";
        rule succeeds;
    if a subject is pending:
        choose a random row in the Table of Offhand Reminiscences;
        say "[line entry][paragraph break]".

Table of Offhand Reminiscences
line
"'It actually is kind of a funny story about [the random pending subject],' [Nathan] remarks casually."
"[Nathan] chuckles under his breath. 'Man, I hadn't thought about [the random pending subject] in ages.'"
"He glances sideways at you. 'It's nothing personal, you know, but I don't feel comfortable discussing [the random pending subject] with just anyone.'"
"'I don't know why I brought up [the random pending subject] just now,' [Nathan] comments. 'Don't mention it to anyone, if you don't mind.'"
"'Okay, see, the thing about [the random pending subject] is...' [paragraph break]'Yes?' you ask, on cue.[paragraph break]'...never mind.'"
"[Nathan] makes an explosive exasperated sound. 'Don't you want to ask me about [the random pending subject]?' he demands."

Test me with "highlighting bright / put sculpture on pedestal / put it on table / put it on sickbed / drop it / think / ask nathan about breakage / think / ask him about generator / ask him about dreams / ask him about gift / ask him about shari / ask him about scar".

RB §7.12. Characters Following a Script

So far we've seen characters who will answer questions whenever the player feels like asking, and characters who will use some reasoning procedure to direct the conversation. There is a third option, often useful in IF with a fast-paced narrative: the character follows a conversational script, making sure to cover a series of points before the scene ends.

There are more and less tedious ways to implement this kind of scene. The worst case is one in which the player is not allowed to interrupt or ask any questions; he must merely wait until the character runs out of things to say. This can be useful and plausible in very small doses - say, two or three turns - but if the character has more information than that to impart, we may want to make the scene more interactive.

Pine 2 ★★★ partly addresses this challenge: the character has a line of conversation that she wants to follow to its conclusion; we may ask questions along the way, but if we're silent, she'll take up the slack, and the scene won't end until she's done with what she has to say.

Another kind of script is a series of actions for the character to perform. Robo demonstrates a programmable robot that will observe what the player does, then try to emulate the actions later when switched into play-back mode. Robo 2 ★★★ extends this capacity to allow the robot to contain fifteen different scripts which the player can store, list, run, and erase.

Your Mother Doesn't Work Here offers a character with a list of tasks but whose plans can be interrupted by more urgent demands. This verges on not being a simple script any more: if we carry the idea to its natural conclusion, we get characters capable of planning scripts for themselves to accomplish their aims. This is conventionally called "goal-seeking".

See also

Goal-Seeking Characters for characters that work out plans for themselves in order to accomplish various outcomes

Examples

426. Robo 1

paste.png "Robo"

The Experimentation Chamber is a room. Robo is a man in the Experimentation Chamber. "Robo, your prototype tin companion, stands awkwardly beside you. In the middle of his chest is a red enamel button[if the red button is switched on], currently depressed[otherwise], currently un-depressed[end if]."

The red button is a device. It is part of Robo. Instead of pushing the red button: if the red button is switched off, try switching on the red button; otherwise try switching off the red button.

After switching on the red button:
    say "CLICK! Robo is now in play-back mode."

After switching off the red button:
    say "CLACK! Robo is now in observation mode."

Definition: Robo is watching if the red button is switched off.

The current instruction set is a list of stored actions that varies.

After doing something when Robo is watching and Robo can see the player:
    now the actor is Robo;
    add the current action to the current instruction set;
    now the actor is the player;
    say "Robo watches you [the current action][one of], his yellow eyes lamp-like and observant[or]. In his metal head, gears whirr[or], his brushed-copper handlebar moustaches twitching[or] impassively[at random].";
    continue the action.

Every turn when Robo is not watching:
    if the number of entries in the current instruction set is 0:
        say "Robo has run out of behavior and grinds to an (expectant) halt.";
        now the red button is switched off;
    otherwise:
        let the next task be entry 1 of the current instruction set;
        try the next task;
        remove entry 1 from the current instruction set.

The red block and the blue cylinder are things in the Experimentation Chamber. The counter is a supporter in the Experimentation Chamber. The counter is scenery.

Report Robo examining Robo:
    say "Robo examines each of his hands in turn, then each of his legs (bending over mostly double in the middle to do this)." instead.

Report Robo examining the player:
    say "Robo stares at you, unblinkingly, for several seconds together[if a random chance of 1 in 7 succeeds]. His left moustache-bar twitches infinitesimally upward[end if]." instead.

Report Robo taking the cylinder:
    say "[one of][Robo] needs several attempts to get his metal fingers around [the cylinder] -- they are not designed for grasping small objects elegantly. But at last he succeeds[or]Once again, Robo struggles a bit before picking up [the cylinder][stopping]." instead.

Test me with "z / take cylinder / take block / put cylinder on counter / put block on counter / x robo / x me / get block / drop block / press red button / z / z / z / z / z / z / z / z / z / z".

434. Your Mother Doesn't Work Here

Suppose the player's mother is supposed to be cleaning the living room, but she can be interrupted by the need to pick up things the player has dropped. New tasks are added to the end of her "current plan" list; every turn, she attempts to do whatever is the last entry on that list.

paste.png "Your Mother Doesn't Work Here"

A person has a list of stored actions called the current plan.

Every turn:
    repeat with culprit running through people who are not the player:
        if the number of entries in current plan of the culprit is greater than 0:
            let N be the number of entries in the current plan of the culprit;
            try entry N of the current plan of the culprit;
            remove entry N from the current plan of the culprit.

The Living Room is a room. It contains a somewhat muddy Persian rug. Your mother is a woman in the Living Room.

West of the Living Room is the Kitchen.

Instead of your mother rubbing the rug:
    say "Your mother scrubs the stained areas of the rug, muttering to herself."

Instead of taking something:
    say "Nah, Mom'll get that."

Report your mother taking something:
    say "Your mother picks up [the noun][one of], sighing deeply[or], jaw tight[or], with assorted comments on your manners[or]; to judge from her comments, she is also indulging in a pleasant fantasy about Swiss boarding schools[stopping]." instead.

When play begins:
    add mother going west to the current plan of mother;
    add mother rubbing the rug to the current plan of mother.

Every turn:
    if mother is not in the Living Room, end the story finally.

Carry out dropping something:
    add mother taking the noun to the current plan of mother.

The player carries some dirty socks, some dirty shoes, a dirty hat, a pair of dirty trousers, and a backpack.

Test me with "drop socks / z / drop shoes / drop hat / drop all / z / z".

As goal-seeking goes, this is fairly rudimentary; "Boston Cream" provides an alternative (and slightly more sophisticated approach), but for really complex goal-seeking characters, it is probably best to turn to the character extensions designed for Inform.

161. Pine 2 ★★★

paste.png "Pine"

A person can be asleep or awake. A person can be active or passive.

The Spinning Tower is a room. "A remote corner of the old castle, reserved for spinning and weaving tasks."

Sleeping Beauty is an asleep woman in the Spinning Tower. "[if asleep]Sleeping Beauty lies here, oblivious to your presence[otherwise]Sleeping Beauty stands beside you, looking a little confused[end if]." The description is "She is even more magnificent than the rumors suggested." Understand "woman" or "girl" or "princess" or "lady" as Sleeping Beauty.

Discovery is a scene. Discovery begins when play begins. Discovery ends when Sleeping Beauty is awake. Marriage Proposal is a scene. Marriage Proposal begins when Discovery ends.

When Discovery ends: say "Throughout the palace you can hear the other sounds of stirring and movement as the spell of centuries is broken."

Instead of waking an awake person: say "Redundant."

Instead of waking an asleep person: say "Yes, but how?"

Instead of attacking an asleep person:
    now the noun is awake;
    say "[The noun] sits bolt upright. 'Hey! Ow!' So much for that true love's kiss nonsense."

Instead of kissing an asleep person:
    now the noun is awake;
    say "[The noun] slowly stirs to wakefulness!"

Instead of throwing water at an asleep person:
    now the second noun is awake;
    now the noun is nowhere;
    say "You pour out [the noun] on [the second noun].

[The second noun] wakes, shuddering. 'Agh! I had a terrible dream about drowning and then-- Hey!'"

The player carries a jug of water. Understand "pour [something] on [something]" or "splash [something] at/on [something]" as throwing it at.

So much, we had before. Now, suppose we want a conversation style which allows the player to move conversation forward by asking appropriate questions, but which will keep moving forward even if he doesn't. To this end, we provide a table -- a borrowing from a later chapter. In the table, we record two ways of performing each conversation bit, one which reflects the player's participation, and one in which the character moves things onward:

Table of Conversation

topic

reply

quip

"dream/dreams/nightmare/nightmares/sleep"

"'Sleep well?' you ask solicitously.

'Not really,' she replies, edging away from you. So much for that angle."

"'Ghastly nightmares,' she remarks. You nod politely."

"marriage/love/wedding/boyfriend/beau/lover"

"'So,' you say. 'This is a little weird since we just met, but, um. Would you like to get married?'

She looks at you nervously. 'Do I have to?'"

"'I, er,' she says. 'I hope I'm not supposed to marry you or something.'"

"marriage/love/wedding/boyfriend/beau/lover"

"'I was told I was going to marry you and inherit the kingdom,' you say, apologetically. 'Would that be very bad?'

'Oh, it's not you -- I'm seeing someone,' she says, smiling quickly.

You try to think how to point out that it's been a hundred years since she last saw her boyfriend."

"'Do you think I could go look for someone? I'm seeing him, you see, and I think I've been... sick... for a while, so he might be worried.'

You try to think how to point out that it's been a hundred years since she last saw her boyfriend."

"marriage/love/wedding/boyfriend/beau/lover"

"'You've been up here for a hundred years,' you say. An unpleasant thought occurs to you. 'Was your young man in the castle somewhere?'

She shakes her head mutely."

"She goes to the window and looks out at the now-fading thicket of briar. 'That took a while to grow,' she observes. 'I've been up here longer than I thought.'

You shrug, uncomfortable."

Instead of asking an awake beauty about a topic listed in the Table of Conversation:
    now Beauty is passive;
    say "[reply entry][paragraph break]";
    blank out the whole row.

The "now Beauty is passive" line prevents her from making any conversation of her own on a turn when we've spoken to her. This keeps the conversation from progressing too quickly.

Instead of telling an awake beauty about something: try asking the noun about it.

Instead of asking an asleep person about something:
    say "[The noun] snores."

Marriage Proposal ends when the number of filled rows in the Table of Conversation is 0.

Every turn during Marriage Proposal:
    if Beauty is active:
        repeat through Table of Conversation:
            say "[quip entry][paragraph break]";
            blank out the whole row;
            make no decision.

After we've generated any spontaneous conversation, we return her to her regular active state.

Every turn: now Beauty is active.

When Marriage Proposal ends: end the story saying "This is going to take some explaining."

Test me with "x beauty / wake beauty / pour water on beauty / ask beauty about sleep / z / ask beauty about marriage".

Now we have a scenario in which the player can ask her some questions out of order if he really wants to, but the scene will not end until the basic conversation topics have been exhausted. If we wanted to add some other chit-chat, not as part of the main conversation strand, but by way of optional enrichment, we might make a second conversation table and record alternative outcomes in it.

429. Robo 2 ★★★

We have seen how we can make a robot that watches the player, then plays back the same actions again. A slightly more adventurous implementation would be to let the player create a whole series of named scripts which the robot will run on command.

To do this, we'll need each program to have a command that sets it off (stored as text, since this is the best way to capture and preserve arbitrary text entered by the player) and then the script of actions that must result:

paste.png "Robo 2"

Use dynamic memory allocation of at least 16384.

Chapter 1 - Programming

Section 1 - The Programs Themselves

The hard drive is a container. A program is a kind of thing. 15 programs are in hard drive. A program has some text called the starter command. A program has a list of stored actions called the script. Understand the starter command property as describing a program.

Rule for printing the name of a program (called the target) which is not blank:
    say "[starter command of the target in upper case]".

Definition: a program is blank if the number of entries in its script is 0.

The current instruction name is some text that varies. The current instruction set is a list of stored actions that varies.

Now, we want to let Robo learn new programs; for this purpose, we'll emulate the code from our previous implementation, so that Robo watches what the player does and stores those actions in his script:

Section 2 - Learning New Programs

Understand "learn [text]" as learning. Learning is an action applying to one topic.

Check learning:
    say "You have already learned all you need to know. Robo, however, remains to be trained." instead.

Check Robo learning:
    if Robo is watching, say "Robo is already recording '[the current instruction name]'." instead.

Carry out Robo learning:
    truncate the current instruction set to 0 entries;
    now the current instruction name is the topic understood;
    now Robo is watching.

Report Robo learning:
    say "'Learning [the current instruction name in upper case],' Robo replies."

After doing something when Robo is watching and Robo can see the player:
    now the actor is Robo;
    add the current action to the current instruction set;
    now the actor is the player;
    say "Robo watches you [the current action][one of], his yellow eyes lamp-like and observant[or]. In his metal head, gears whirr[or], his brushed-copper handlebar moustaches twitching[or] impassively[at random].";
    continue the action.

Of course, we also need to be able to switch learning mode off, and store any script learned this way. We'll also use the same STOP command to make Robo terminate a program he's in the middle of running.

Section 3 - Returning to Standby Mode

Understand "stop" as stopping. Stopping is an action applying to nothing.

Check stopping:
    say "The command is useful only for Robo." instead.

Check Robo stopping:
    if Robo is standing by, stop the action.

Carry out Robo stopping when Robo is watching:
    let N be a random blank program;
    if N is a program:
        now the starter command of N is the current instruction name;
        now the script of N is the current instruction set;
        say "'Stored [current instruction name in upper case].'";
    otherwise:
        say "FAILURE: no program slots remaining."

Carry out Robo stopping:
    now Robo is standing by.

Report Robo stopping:
    say "Robo is now standing by."

Next, we need to be able to play these programs back again. We'll give Robo a "current program" to store which program he's currently working on, and a number called "stage" which will record where he is in the script. Our previous implementation simply had Robo erase entries from his script list as he performed them, but this time we would like Robo to be able to remember and rerun the same scripts over and over, so we need something a little more subtle.

Section 4 - Running Learned Programs

Understand "run [any program]" as running. Running is an action applying to one visible thing.

Check running:
    say "Only Robo can perform Robo's programs." instead.

Check Robo running:
    if Robo is not standing by, stop the action.

Unsuccessful attempt by Robo running:
    say "'ERROR: Robo can launch new programs only when on standby.'"

Carry out Robo running:
    now the current program of Robo is the noun;
    now the stage of Robo is 1;
    now Robo is replaying.

Report Robo running:
    say "'Running [the starter command in upper case],' Robo confirms."

Every turn when Robo is replaying:
    let the chosen script be the script of the current program of Robo;
    let maximum be the number of entries in the chosen script;
    let N be the stage of Robo;
    let the next step be entry N of the chosen script;
    try the next step;
    increment the stage of Robo;
    if the stage of Robo is greater than the maximum:
        say "Robo's program ends, and he reverts to stand-by mode.";
        now Robo is standing by;
        now the stage of Robo is 1.

For the player's sanity, we should also provide a way to find out which programs Robo has stored in memory and what they do, so we design two listing commands:

Section 5 - Listing Learned Programs

Understand "list programs" as requesting program list. Requesting program list is an action applying to nothing.

Check requesting program list:
    say "You will have to ask Robo to list programs." instead.

Carry out Robo requesting program list:
    say "'The available program[if more than one program is not blank]s[end if] [is-are list of programs which are not blank].'".

Understand "describe [any program]" or "list [any program]" as requesting script of. Requesting script of is an action applying to one visible thing.

Check requesting script of:
    say "You will have to ask Robo to give you the script." instead.

Carry out Robo requesting script of:
    say "The script of [noun] is: [script of the noun]."

And to complete the suite, in case the player runs into Robo's fifteen-program limit:

Section 6 - Deleting Learned Programs

Understand "delete [any program]" as deleting. Deleting is an action applying to one visible thing. Understand the command "erase" as "delete".

Check deleting:
    say "You will have to instruct Robo to delete [the noun]." instead.

Check Robo deleting (this is the can't delete except in standby rule):
    if Robo is not standing by, stop the action.

Unsuccessful attempt by Robo deleting:
    say "'ERROR: programs may only be deleted while Robo is in stand-by mode.'" instead.

Carry out Robo deleting:
    truncate the script of the noun to 0 entries;
    now the starter command of the noun is "".

Report Robo deleting:
    say "'Program deleted.'"

Now we use pretty much the same set-up as before to test Robo's abilities:

Chapter 2 - The Scenario

The Experimentation Chamber is a room.

Robo is a man in the Experimentation Chamber. "Robo, your prototype tin companion, stands awkwardly beside you[if watching], watching[end if]." Robo can be watching, replaying, or standing by. Robo is standing by. Robo has a program called the current program. Robo has a number called the stage.

Persuasion rule: persuasion succeeds.

The red block and the blue cylinder are things in the Experimentation Chamber. The counter is a supporter in the Experimentation Chamber. The counter is scenery.

Report Robo examining Robo:
    say "Robo examines each of his hands in turn, then each of his legs (bending over mostly double in the middle to do this)." instead.

Report Robo examining the player:
    say "Robo stares at you, unblinkingly, for several seconds together[if a random chance of 1 in 7 succeeds]. His left moustache-bar twitches infinitesimally upward[end if]." instead.

Report Robo taking the cylinder:
    say "[one of][Robo] needs several attempts to get his metal fingers around [the cylinder] -- they are not designed for grasping small objects elegantly. But at last he succeeds[or]Once again, Robo struggles a bit before picking up [the cylinder][stopping]." instead.

Test me with "test chocolate / test vanilla".

Test chocolate with "learn chocolate / stop / list programs / Robo, learn chocolate / take red / put all on counter / Robo, stop / Robo, list programs / Robo, run chocolate / z / Robo, run chocolate / Robo, stop / z".

Test vanilla with "Robo, learn vanilla / take all / i / drop all / x robo / x me / Robo, stop / Robo, list programs / Robo, list vanilla / Robo, run vanilla / z / z / robo, delete vanilla / robo, stop / robo, list vanilla / robo, delete vanilla / robo, list programs".

We could also have written this so that Robo learns new scripts by accepting the player's instructions, so that

>ROBO, LEARN LIBRARY THEFT
>ROBO, TAKE BOOK
>ROBO, EAST
>ROBO, STOP

...would store the script 'library theft' with the actions taking the book and going east. The implementation there would have been mostly identical, except that instead of an "after doing something..." rule, we would have captured commands as we asked Robo to perform them, and added those to the command list in progress. The alternative code might look something like this:

Before Robo doing something other than stopping when Robo is watching:
    add the current action to the current instruction set;
    say "'CHECK: [current action] added to script,' says Robo." instead.

Unsuccessful attempt by Robo doing something when Robo is watching:
    say "He does not actually perform the action."

RB §7.13. Traveling Characters

There are a number of ways we can make characters navigate our map. We might reasonably want them to approach and follow the player (as in Van Helsing ★★); or to allow the player to follow characters who have left the room (as in Actaeon ★★).

Characters who are less interested in the player will more likely follow their own courses around the available geography, however. A character may move randomly from room to room, as demonstrated in Mistress of Animals; he may follow a path that we have specifically written in advance, as Odyssey ★★ shows; or, most elegantly, he may use the "best route" calculation to find the best possible way to a given target room, as seen in Latris Theon ★★★.

This final method is arguably the neatest solution to character movement, allowing for characters to act in sophisticated ways; if we incorporate the Locksmith extension, other characters will even unlock and open doors that are in their way. The chief catch is that it should not be used too profligately with large numbers of characters, since on slow machines the processing power required to plan all their travel will make a noticeable difference to the running speed of the story.

All the same, the constraints are not so severe as to preclude having a moderate number of route-finding characters all wandering around at once. This does introduce a new problem, however: movement descriptions can become hard to follow if every turn produces long reams of reports such as

Joe enters the room from the south.
Lawrence opens the gate.
Lawrence departs to the west.
Lucy comes in from above.
Ted enters the room from the south.
Bill departs to the west.

Patient Zero ★★★★ tackles this problem by calculating all of the character movement without printing any text; it then combines similar or related events into coherent paragraphs, as in

Rhoda and Antony walk into the Post Office. Rhoda could have been rolling in chocolate and Antony looks as though dipped in french vanilla.

or

Antony opens the iron gate. He goes through.

See also

Doors, Staircases, and Bridges for some technical details of allowing other characters to interact with doors when they're in rooms that don't contain the player

Examples

77. Mistress of Animals

Suppose we want a restless sort of character always pacing from room to room. It is quite easy to use adjacency to achieve this effect:

paste.png "Mistress of Animals"

Corinth is a room. Athens is east of Corinth. Epidaurus is southeast of Corinth and east of Mycenae. Mycenae is south of Corinth. Olympia is west of Mycenae. Argos is south of Mycenae. Thebes is northwest of Athens. Pylos is south of Olympia. Sparta is east of Pylos and south of Argos. Delphi is northwest of Thebes.

Artemis is a woman in Thebes.

Every turn:
    if Artemis is in a room (called the current space):
        let next space be a random room which is adjacent to the current space;
        if Artemis is visible, say "Artemis heads to [the next space].";
        move Artemis to next space;
        if Artemis is visible, say "Artemis arrives from [the current space]."

Test me with "z / z / z / z / z / z".

Of course, it helps that Artemis is the sort to like open spaces. The implementation would become more complicated if there were doors which might block transit between these locations.

39. Van Helsing ★★

Suppose we want to write a character who tries to be in the same room as the player. We will do this by testing every turn whether the character's location and the player's location are the same; if the answer is no, the character will look for a path to the player's location, then try to move along that path. (We will learn more about finding paths and giving characters instructions later.)

The result will be that if the player ever moves to another location, the character will automatically pursue him.

paste.png "Van Helsing"

The Drawbridge is a room. North of the Drawbridge is the Immensely Enormous Entry Hall. West of the Entry Hall is the Vast Dining Area. North of the Vast Dining Area is the Colossal Kitchen. The Spooky Guano-filled Attic is above the Entry Hall.

Count Dracula is a man in the Attic.

In the following condition, we could also have written "if the location of Count Dracula is not the location", because "location" by itself is always understood to be the player's location. But it seemed better for clarity to write it this way:

Every turn:
    if the location of Count Dracula is not the location of the player:
        let the way be the best route from the location of Count Dracula to the location of the player, using doors;
        try Count Dracula going the way;
    otherwise:
        say "'Muhahaha,' says Count Dracula."

Test me with "z / z / n / w / e / u / z / d".

274. Odyssey ★★

paste.png "Odyssey"

Corinth is a room. Athens is east of Corinth. Epidaurus is southeast of Corinth and east of Mycenae. Mycenae is south of Corinth. Olympia is west of Mycenae. Argos is south of Mycenae. Thebes is northwest of Athens. Pylos is south of Olympia. Sparta is east of Pylos and south of Argos. Delphi is northwest of Thebes.

Athena is a woman in Athens.

Athena will proceed, unless delayed, through a list of locations stored in a simple table. Rather than using Inform's route-finding abilities ("the best route from..."), we simply move Athena from one location to the next, not even using the going action: she moves in mysterious ways, as befits a goddess.

Table of Athena's Movement
destination
Thebes
Delphi
Thebes
Athens
Corinth
Mycenae

Every turn when Athena is active:
    repeat through the Table of Athena's Movement:
        let last space be the location of Athena;
        if Athena can be seen by the player, say "Athena heads to [the destination entry].";
        move Athena to destination entry;
        if Athena can be seen by the player, say "Athena arrives from [the last space].";
        blank out the whole row;
        break.

By blanking out the table line by line, we make sure that we never lose our place in the path.

Since we want the player to be able to talk to Athena, we need a way to stall her in her path, as well.

Athena can be active or passive. Athena is active.

Before doing something to Athena:
    now Athena is passive;
    say "Athena waits around patiently, though you can tell she would like to leave..."

Instead of telling Athena about something:
    say "She watches you patiently as though to say that she already knows."

Instead of asking Athena about something:
    say "Her response is inscrutably ancient and Greek. Afterwards you remember only the flash of bright eyes."

Finally, we do need to wake Athena up again if she has become passive. The following rule will occur after the movement rule just because of code ordering, though we could make matters more explicit if we needed to:

Every turn when Athena is passive:
    now Athena is active.

Test me with "east / northwest / wait / examine athena / wait".

302. Actaeon ★★

Suppose we want the player to be able to go after characters who are moving around the map. The trick, of course, is that once characters are gone they are no longer visible to "follow [person]", so we need "follow [any person]" to find them.

paste.png "Actaeon"

A person has a room called last location.

Understand "follow [any person]" as following. Understand the commands "chase" and "pursue" as "follow".

Following is an action applying to one visible thing.

Check following:
    if the noun is the player, say "Wherever you go, there you are." instead;
    if the noun is visible, say "[The noun] is right here." instead;
    if the last location of the noun is not the location, say "It's not clear where [the noun] has gone." instead.

Here again the best route comes in handy:

Carry out following:
    let the destination be the location of the noun;
    if the destination is not a room, say "[The noun] isn't anywhere you can follow." instead;
    let aim be the best route from the location to the destination;
    say "(heading [aim])[line break]";
    try going aim.

Corinth is a room. Athens is east of Corinth. Epidaurus is southeast of Corinth and east of Mycenae. Mycenae is south of Corinth. Olympia is west of Mycenae. Argos is south of Mycenae. Thebes is northwest of Athens. Pylos is south of Olympia. Sparta is east of Pylos and south of Argos. Delphi is northwest of Thebes.

Artemis is a woman in Corinth.

We do also have to make sure that whenever we move a person from room to room, we record where they were moved from; otherwise, our clever restrictions about whom the player can pursue will not work properly.

To move (pawn - a person) tidily to (target - a room):
    now the last location of the pawn is the holder of the pawn;
    move the pawn to the target.

Every turn:
    let current location be the location of Artemis;
    let next location be a random room which is adjacent to the current location;
    if Artemis is visible, say "Artemis heads to [the next location].";
    move Artemis tidily to next location;
    if Artemis is visible, say "Artemis arrives from [the current location]."

Test me with "wait / follow artemis / follow artemis / follow artemis".

185. Latris Theon ★★★

To begin with, we create an action for going to a named place. All that this action will do is to change that person's hoped-for destination: the actual moving around comes later.

paste.png "Latris Theon"

A person has a room called destination.

Understand "go to [any room]" as going vaguely.

Going vaguely is an action applying to one visible thing.

Carry out someone going vaguely:
    now the destination of the person asked is the noun.

Report someone going vaguely:
    say "[The person asked] looks amused, but accepts the commission to go to [the noun]."

It stands to reason the player plays Zeus or at the very least Apollo, but let's not let this go to the player's head. Note that the following rule applies to the player, but not to anyone else, so HERMES, GO TO ATHENS will work but GO TO ATHENS will not.

Carry out going vaguely:
    say "You're too thoroughly lost."

And finally we recreate Greece and one of its heroes.

Corinth is a room. Athens is east of Corinth. Epidaurus is southeast of Corinth and east of Mycenae. Mycenae is south of Corinth. Olympia is west of Mycenae. Argos is south of Mycenae. Thebes is northwest of Athens. Pylos is south of Olympia. Sparta is east of Pylos and south of Argos. Delphi is northwest of Thebes.

Hermes is a man in Corinth. The destination of Hermes is Corinth. [So he is initially happy where he is.] Persuasion rule for asking Hermes to try going vaguely: persuasion succeeds. [But he is open to suggestions.]

Every turn when the destination of Hermes is not the location of Hermes:
    let the right direction be the best route from the location of Hermes to the destination of Hermes;
    try Hermes going the right direction.

Test me with "hermes, go to athens / e".

It simplifies matters that our map of Greece makes it possible to reach any location from any other location, by some sequence of movements: if there were an isolated location -- say, Crete -- with no map connection to the mainland, then we would have to worry about the "right direction" not being a direction at all. The following version of Hermes' trekking rule is protected against the possibility:

Every turn when the destination of Hermes is not the location of Hermes:
    let the right direction be the best route from the location of Hermes to the destination of Hermes;
    if the right direction is a direction, try Hermes going the right direction.

402. Patient Zero ★★★★

paste.png "Patient Zero"

Use the serial comma and no scoring.

Understand "about" as asking for information. Asking for information is an action out of world.

Carry out asking for information: say "An implementation of the following creative brief:

People wander around some small map, on errands. One, sad to tell, has Gelato's Syndrome, a tragic condition turning one's skin the colour of a random flavour of ice cream (raspberry ripple, neapolitan, etc.). When two people are in the same room, there's a 1/3 chance that an infected person will infect a non-infected one. The player can cure any single person: victory condition - to stamp out the disease."

When play begins:
    say "Gelato's Syndrome. It's struck, and it's struck hard. In these sticky summer months, there's no telling who will contract the disease next.";
    now the command prompt is "[if the destination of the player is not blank](heading to [destination of the player]) [end if]>".

Section 1 - Errands

The current actor is a person which varies. The current owner is a person which varies.

Every turn:
    if player is active, follow the character movement rules.

Every turn:
    now the last person named is the player;
    now the last thing named is the player;
    now every person is active.

A person can be active or passive. The player is passive.

The character movement rules are a rulebook.

The first character movement rule:
    now group size is 1;
    now the last person named is the player;
    now the last thing named is the player;
    now the player is passive.

A character movement rule:
    repeat with mover running through innocent people:
        now the current actor is the mover;
        follow the shopper rules;
        now the current actor is passive;
    follow the movement reporting rule.

A character movement rule:
    repeat with next mover running through mercantile people:
        now the current owner is the next mover;
        follow the shopowner rules;
        now the current owner is passive;
    follow the infection rule.

To decide whether movement has not yet occurred:
    if the player is passive, no;
    yes.

Definition: a person is mercantile if it owns a room. Definition: a person is innocent if it is not mercantile and it is not the player.

The shopowner rules is a rulebook.

A shopowner rule:
    let the shop be a random room owned by the current owner;
    if the shop is air-conditioned and an open door (called the escape) protects the shop, try the current owner closing the escape instead.

Report someone closing a door when the person asked owns the location:
    say "[The person asked], muttering darkly about air-conditioning and electricity, closes [the noun]." instead.

Report Vanessa closing the metal door when the metal door is visible:
    if Vanessa is visible, say "Vanessa watches serenely as the metal door slides automatically back in place, sealing Cold Comfort." instead;
    otherwise say "The metal door slides heavily back into place." instead.

A shopowner rule:
    if the location of the current owner encloses a submitted artwork (called the target):
        try the current owner filing the target.

Filing is an action applying to one thing.

Before someone filing something which is not carried by the person asked:
    try the person asked taking the noun instead.

Carry out someone filing:
    if the person asked does not carry the noun and the person asked is visible, say "[The person asked] tries unsuccessfully to get [the noun]." instead;
    now the noun is nowhere.

Report someone filing:
    say "[The person asked] registers [the noun] and files it away."

The shopper rules is a rulebook.

A shopper rule:
    if the current actor carries something (called the problem), try the current actor resolving the problem instead.

A shopper rule:
    if the current actor is not in the pool hall and the air conditioner is switched on:
        try the current actor approaching the pool hall;
    otherwise:
        let way be a random direction;
        try the current actor going the way.

Definition: a room is air-conditioned:
    if it is outdoors, no;
    if it is the Pool Hall and the air conditioner is switched off, no;
    if it is protected by a door, yes;
    no.

Protection relates a door (called X) to a room (called Y) when the front side of X is Y or the back side of X is Y. The verb to protect means the protection relation.

Ownership relates one person to various rooms. The verb to own means the ownership relation.

Resolving is an action applying to one thing.

An artwork is a kind of thing. Before printing the name of an artwork, say italic type. After printing the name of an artwork, say roman type. An artwork can be submitted or reserved.

A book is a kind of artwork.

Before someone resolving a book when the person asked is not in the Public Library:
    try the person asked approaching the Public Library instead.

Carry out someone resolving a book:
    move the noun to the Public Library;
    now the noun is submitted.

Report someone resolving a book:
    say "[The person asked] turns in [the noun]."

Before listing contents: group books together.

Before grouping together books: say "books entitled ".

A stamped envelope is a kind of thing.

Before someone resolving a stamped envelope when the person asked is not in the Post Office:
    try the person asked approaching the Post Office instead.

Carry out someone resolving a stamped envelope:
    now the noun is nowhere.

Report someone resolving a stamped envelope:
    say "[The person asked] slips [a noun] into the outgoing mail slot."

Instead of someone resolving a stamped envelope when the person asked carries at least two stamped envelopes:
    if the person asked is visible, say "[The person asked] shoves into the mail slot [a list of stamped envelopes carried by the person asked].";
    repeat with item running through stamped envelopes carried by the person asked:
        now the item is nowhere.

A DVD is a kind of artwork.

Before someone resolving a DVD when the person asked is not in the Rental Store:
    try the person asked approaching the Rental Store instead.

Carry out someone resolving a DVD:
    now the noun is submitted;
    move the noun to the Movie Rental Store.

Report someone resolving a DVD:
    say "[The person asked] returns [the noun]."

Instead of someone resolving a DVD when the person asked carries at least two DVDs:
    if the person asked is visible, say "[The person asked] turns in [a list of DVDs carried by the person asked].";
    now every DVD carried by the person asked is submitted;
    now every DVD carried by the person asked is in the location of the person asked.

Before listing contents: group DVDs together.

Before grouping together DVDs: say "DVDs of ".

Approaching is an action applying to one thing.

Carry out someone approaching:
    let the way be the best route from the location of the person asked to the noun, using doors;
    if the way is a direction, try the person asked going the way;
    otherwise stop the action.

A coupon is a kind of thing.

Carry out someone resolving a coupon:
    try the person asked giving the noun to Vanessa.

The block giving rule is not listed in any rulebook.

Check giving something to someone (this is the block player giving rule):
    abide by the block giving rule.

Before someone resolving a coupon when the person asked is not in Cold Comfort:
    try the person asked approaching Cold Comfort instead.

After someone giving a coupon to Vanessa:
    let the reward be a random ice cream cone;
    let the new flavor be a random infection color;
    now the infection color of the reward is the new flavor;
    move the reward to the person asked;
    now the noun is nowhere;
    if Vanessa is visible, say "[The person asked] trades in [the noun] and receives [a reward] from Vanessa."

Infection color is a kind of value. The infection colors are french vanilla, whole-bean vanilla, mint, chocolate, dark chocolate, chocolate chip, chocolate fudge, mint chocolate chip, chocolate chocolate chip, triple chocolate, white chocolate, white chocolate chip, aztec cocoa-chili, raspberry ripple, neapolitan, rum raisin, dulce de leche, strawberry chunk, rocky road, blackberry sorbet, lemon sherbet, lime ice, caramel swirl, mango, saffron silk, and cookie dough cream.

To say list of flavors:
    let current color be french vanilla;
    while current color is not cookie dough cream:
        say "[current color], ";
        now current color is the infection color after the current color;
    say "and [current color]".

Understand "ask vanessa for [flavored ice cream]" as buying the flavor. Understand "buy [flavored ice cream]" as buying the flavor.

Buying the flavor is an action applying to one infection color.

Check buying the flavor:
    unless the player can see Vanessa:
        say "It would help if you were in the presence of an ice cream salesperson." instead.

Carry out buying the flavor: say "'Do you have a coupon?' Vanessa demands. You admit you do not. 'No [infection color understood] for you!'"

Understand "ice cream" or "cream" or "ice" or "sherbet" or "sorbet" as "[ice cream]".

Understand "[infection color]" or "[infection color] [ice cream]" as "[flavored ice cream]".

An ice cream cone is a kind of thing. An ice cream cone is always edible. An ice cream cone has an infection color. An ice cream cone can be half-eaten or fresh. Understand the infection color property as referring to an ice cream cone.

Carry out someone resolving an ice cream cone:
    try the person asked eating the noun instead.

Instead of someone eating a fresh ice cream cone:
    now the noun is half-eaten;
    if the person asked is visible, say "[The person asked] licks [the noun]."

Report someone eating an ice cream cone:
    say "[The person asked] pops the end of [the noun] into [if the person asked is female]her[otherwise]his[end if] mouth and swallows." instead.

Before printing the name of an ice cream cone:
    say "[if half-eaten]half-eaten [end if][infection color] ".

Section 2 - Infection Rules

This is the infection rule:
    if an infected person (called typhoid mary) can see a clean person (called random bystander) and a random chance of 1 in 3 succeeds:
        try typhoid mary sneezing on the random bystander.

A person can be infected or clean. A person has an infection color.

Every turn:
    if the player is infected, say "You feel itchy."

Definition: a person is other if it is not the player. Definition: a person is another if it is other.

When play begins: now right hand status line is "Sick: [number of infected people]/[number of people]".

Every turn:
    if every person is infected, end the story saying "Everyone succumbs";
    if every person is clean, end the story finally saying "The Syndrome is eradicated".

Understand "sneeze on [something]" as sneezing on. Sneezing on is an action applying to one thing.

Check sneezing on:
    if the player is clean, say "You're not sickly." instead;
    if the noun is the player, say "Ew." instead;
    if the noun is not a person, say "[The noun] cannot be infected." instead.

Carry out sneezing on:
    now the noun is infected;
    now the infection color of the noun is a random infection color.

Carry out someone sneezing on:
    now the noun is infected;
    now the infection color of the noun is a random infection color.

Report sneezing on:
    say "Unable to control yourself, you sneeze on [noun].".

Report someone sneezing on:
    say "[The person asked] sneezes on [if the noun is the player]you[otherwise][noun][end if]!".

Understand "inject [someone] with [something]" as injecting it with. Understand "inject [someone] with [syringe]" as injecting it with. Understand "use [syringe] on [someone]" as injecting it with. Understand the commands "innoculate" and "vaccinate" as "inject".

Injecting it with is an action applying to two things.

Check injecting it with:
    if the second noun is not the syringe, say "[The second noun] cannot inject anything." instead;
    if the noun is clean:
        if the noun is the player, say "You're not infected yet." instead;
        say "[The noun] is not infected, and the syringe contains a cure, not a vaccine." instead.

Carry out injecting it with: now the noun is clean.

After injecting the player with something: say "You inject yourself, wincing at the sting. But the itching fades almost at once."

Report injecting it with: say "You inject [the noun], who is now cured (but could easily be reinfected)."

Section 3 - Geography

Include Locksmith by Emily Short.

Understand "go to/toward/into [any room]" as going toward. Understand "enter [any room]" as going toward.

A person has a room called the destination.

Going toward is an action applying to one thing.

Check going toward:
    if the noun is the location, say "You're already in [the location]." instead.

Carry out going toward:
    now the destination of the player is the noun;
    let heading be the best route from the location to the noun, using even locked doors;
    if heading is not a direction, say "You can't think how to get there from here." instead;
    try going heading;
    if the location is the destination of the player, now the destination of the player is blank.

Instead of waiting when the destination of the player is not blank:
    if the destination of the player is the location:
        now the destination of the player is blank;
    otherwise:
        try going toward destination of the player;
        if the location is the destination of the player, now the destination of the player is blank.

Understand "stop" or "cease" as stopping. Stopping is an action applying to nothing. Carry out stopping: now the destination of the player is blank. Report stopping: say "You stop in your tracks."

After going to an air-conditioned room:
    say "You step into the mercifully air-conditioned surroundings of...";
    continue the action.

After going from an air-conditioned room:
    say "You emerge from the air-conditioning into heat like a wall...";
    continue the action.

Instead of listening to an air-conditioned room:
    say "The air-conditioning hums softly."

The Alfred Cralle Pool Hall is a room. "The town's most popular gathering-place, the pool hall is decorated in honor of the inventor of the ice cream scoop." The air conditioner is a device in the Pool Hall. "[if switched off]An air conditioner sits in the corner, unhappily inert[otherwise]The air conditioner hums briskly[end if]."

The felt door is west of the Pool Hall. The felt door is a door. The felt door is open. The felt door is lockable and unlocked. The key to the city unlocks the felt door. The description of the felt door is "It has a prominent lock, designed for an old-fashioned key."

After locking a door with something in the presence of an other person (called audience):
    say "[The audience] looks a little non-plussed when you lock [the noun], but shrugs."

Nancy Johnson Memorial Square is west of the felt door. The description of Nancy Johnson Memorial Square is "Waves of August heat rise from the pavement: more than once you've had the fancy that your shoes are simply going to stick. At the center of the square, rubbed to a brownish polish by many adoring hands, is the statue of Mrs. Nancy Johnson of New Jersey."

The statue is scenery in Memorial Square. Understand "nancy" or "johnson" or "mrs" as the statue. The description of the statue is "Mrs. Johnson is pictured with a hand-cranked ice cream freezer tucked under one arm. Her other hand grips an ice cream scoop, ready to serve frozen dessert to the huddled masses." A hand-cranked ice cream freezer is part of the statue. The description is "The hand-cranked ice cream freezer was Mrs. Johnson's invention in 1846, though it was William Young who had the sense to patent the thing in 1848." The scoop is part of the statue. The description of the scoop is "An anachronism: Alfred Cralle would not invent the tool until 1897."

The Post Office is northwest of Nancy Johnson Memorial Square. "Service at the post office is on the slow side since everything went automated." The slot is scenery in the post office. The slot is a container. Carry out inserting something into the slot: now the noun is nowhere. Report inserting something into the slot: say "[The noun] falls out of sight, and you know you will never see it again."

Hamwi Street is northeast of an iron gate. "A U-shaped street running from Main Street around to the Memorial Square, Hamwi Street was recently added by ambitious city planners. The small and straggly line of trees has yet to grow enough to provide perceptible shade, so the street is even hotter and more unforgiving than the other parts of town."

The iron gate is northeast of Nancy Johnson Memorial Square. The iron gate is a door. It is lockable and unlocked.

Before printing the name of the iron gate while not opening or closing or locking or unlocking:
    if the person asked is the player:
        if the gate is open, say "open ";
    otherwise if the gate is locked:
        say "locked ";
    otherwise if the gate is closed:
        say "closed ".

Cold Comfort Ice Cream is north of a metal door. The metal door is north of Hamwi Street. A poster is fixed in place in Cold Comfort. "A poster fills one wall with the blazing promise of treats to come." The description of the poster is "Coming soon! Thai ice creams! Durian, jackfruit, taro, and coconut flavors!"

The metal door is a door. "A frosty metallic door separates [the location] from [the other side of the metal door]." The metal door is lockable and unlocked. The key to the city unlocks the metal door.

Marciony Street is southeast of Nancy Johnson Memorial Square. "A semi-circular terrace, named somewhat fancifully after one claimant to the invention of the ice cream cone -- though Hamwi Street competes for the same honor. There are wedges of cool shadow here and there thanks to the buildings, but for the most part the southern exposure keeps Marciony unpleasantly hot."

The Movie Rental Store is west of a glass door. The glass door is a door. It is west of Marciony Street. The glass door is lockable and unlocked. The key to the city unlocks the glass door.

Main Street is southeast of Hamwi Street. Main Street is northeast of some bronze gates.

The emergency box is in Main Street. The emergency box is fixed in place. "A fire-red box with a glass front faces the sidewalk, with 'In case of emergency, BREAK GLASS' lettered on it." The emergency box is closed and transparent. Understand "glass" as the box. Instead of attacking the closed emergency box: say "You hit the emergency box, which shatters open."; now the emergency box is open. Instead of attacking the open emergency box: say "The glass has already been thoroughly broken."

The syringe is in the emergency box. The description of the syringe is "It contains the cure for Gelato's Syndrome. You can inject anyone you like with it."

The bronze gates are northeast of Marciony Street. The bronze gates are a door. The bronze gates are lockable and unlocked. The description of the bronze gates is "Erected during the milk-taint revolution of 1937, they were designed to keep Main Street safe from the depredations of dairy-starved rioters."

The Public Library is east of Main Street. "Built in the 1920s during the height of the dairy boom, the public library has lush pink velvet seats, marble walls the color of fresh cream, and a motif of cherries carved around every doorframe. An incongruous sign hangs from the ceiling." The incongruous sign is scenery in the Public Library. The description of the incongruous sign is "Eating and drinking in the library is STRICTLY PROHIBITED."

Town Hall is southeast of Main Street. "Town Hall was built during the slow days of the ice-cream bust, and therefore it is as joyless and utilitarian as the Public Library is ridiculous. Unwilling to be reminded of their pain, the inhabitants steered clear of any decoration that might remotely be construed to resemble a scoop of anything: so there are no curves, only disciplined right angles." The key to the city is in Town Hall. It unlocks the iron gate. It unlocks the bronze gates. The description of the key to the city is "A skeleton key."

A room can be indoors or outdoors. The Post Office, the Alfred Cralle Pool Hall, the Store, Cold Comfort, Town Hall, and the Library are indoors.

Use full-length room descriptions.

After looking in an outdoors room:
    let started printing be false;
    now every proximate door is not mentioned;
    if an indoors room is adjacent:
        let started printing be true;
        say "From here you can head into [the list of adjacent indoors rooms][if a proximate door is not mentioned], or go through [the list of proximate doors which are not mentioned][end if]. [run paragraph on]";
    if an outdoors room is adjacent:
        say "You could[if started printing is true] also[end if] go ";
        let count be the number of adjacent outdoors rooms;
        let index be count;
        repeat with next room running through adjacent outdoors rooms:
            let way be the best route from the location to the next room;
            say "[way] to [the next room]";
            decrement index;
        make delimiter index of count, continuing;
    if a proximate door is not mentioned:
        let started printing be true;
        say "[if started printing is true]Also available[otherwise]Your available exits[end if] [is-are the list of proximate doors which are not mentioned].";
    otherwise:
        if started printing is true, say paragraph break.

Definition: a door is proximate:
    if the front side of it is the location, yes;
    if the back side of it is the location, yes;
    no.

Before exiting when the player is in an indoors room:
    if the player can see a door (called nearest exit), try entering the nearest exit instead;
    repeat with way running through directions:
        let next room be the room way from the location;
        if the next room is a room, try going way instead.

Blank is a room. The destination of the player is Blank. Blank contains 15 ice cream cones.

Section 4 - Other Players

Vanessa is a woman in Cold Comfort. Vanessa owns Cold Comfort.

Francine is a woman in the Public Library. Francine carries a book called Phlox for Phyllis. Francine carries a stamped envelope called a pink stamped envelope.

Lewis is a man in the Alfred Cralle Pool Hall. Lewis carries 3 stamped envelopes. Lewis carries a book called Idiot's Guide to Dating. Lewis carries a book called How to Meet Women. Lewis carries a book called Seduction in Three Easy Steps. Lewis carries a DVD called Sleepless in Seattle.

Gene is a man in Nancy Johnson Memorial Square. Gene carries a stamped envelope. Gene carries a DVD called Casablanca. Gene carries a coupon.

Rhoda is a woman in Marciony Street. Rhoda carries a book called The Marciony Street Murders. Rhoda carries a DVD called Unsolved Serial Killings XVIII. Rhoda carries a stamped envelope called a squashy package.

Martin is a man in Main Street. Martin carries a DVD called The Lifecycle of the South Sea Tortoise. Martin carries a coupon.

Antony is a man in Movie Rental. Antony carries a coupon. Antony carries a stamped envelope called a postcard.

Shelby is a man in the Town Hall. Shelby carries a DVD called Conducting An Orderly Meeting. Shelby carries 5 stamped envelopes. Shelby carries an ice cream cone. Shelby carries a coupon.

Christopher is a man in the Library. Christopher owns the Library.

Linnea is a woman in the Alfred Cralle Pool Hall. Linnea owns the Alfred Cralle Pool Hall.

Ned is a man in the Movie Rental Store. Ned owns the Movie Rental.

After printing the name of someone (called target) while listing contents: if the target owns the location of the target, say " (the owner)".

The description of a person is usually "[The noun] [if the noun is clean]looks healthy[otherwise]is the color of [infection color of the noun][end if]."

After examining another person who is carrying something: say "[if the noun is female]She[otherwise]He[end if] is carrying [a list of things carried by the noun]."

When play begins: let Patient Zero be a random other person; now patient zero is infected.

This is a light variation of a previous example, but we use it here because it is convenient:

Section 5 - Conversation

A person has a table name called conversation.

Instead of asking someone about something:
    let the source be the conversation of the noun;
    if topic understood is a topic listed in source:
        if there is a turn stamp entry:
            say "You have already heard that [summary entry].";
        otherwise:
            now turn stamp entry is the turn count;
            now the character entry is the noun;
            say "[reply entry][paragraph break]";
    otherwise:
        say "[The noun] stares at you blankly.".

Instead of telling someone about something:
    try asking the noun about it.

Understand "recap" or "recall" or "review" as recalling conversations.

Recalling conversations is an action applying to nothing.

Carry out recalling conversations:
    repeat with speaker running through other people:
        let source be the conversation of the speaker;
        sort source in turn stamp order;
        say "[The speaker] has so far told you: [line break]";
        let index be 0;
        repeat through source:
            if there is a turn stamp entry and the speaker is character entry:
                let index be 1;
                say " [summary entry][line break]";
        if index is 0, say " absolutely nothing[line break]";
        say line break.

The conversation of a person is usually Table of General ChitChat.

Table of General ChitChat

topic

reply

summary

turn stamp

character

"weather/heat/warmth"

"'It's appalling, isn't it? You'd think we didn't pay our taxes.'"

"that the weather is appalling"

a number

a person

"sun/sunlight"

"'Good thing the town mostly switched to solar power, har, har.'"

"that the town is mostly relying on solar power"

"rain"

"'Nope, there isn't going to be rain for 132 days,' replies [the noun]."

"that rain is not expected for another 132 days"

"snow/hail/ice"

"This hilarious sally is greeted with hoots of laughter only."

"that the concept of snow is downright laughable"

"disease/sickness/illness/syndrome"

"You get a cold, fixed stare in response. 'That's not funny,' [the noun] replies finally."

"that discussing the disease is more or less taboo"

"cold comfort"

"'If you haven't tried it, you should,' says [the noun]. 'Best ice cream in town, and that's saying something, you bet.'"

"that Cold Comfort has the best ice cream in town"

"town/city/village"

"'Yeah, it's a mite odd,' allows [the noun]. 'Not to everyone's taste, like...' [the noun as pronoun] considers for a moment. 'Like ginger ice cream. Big pieces of crystallized ginger... not everyone likes that.'"

"that the town is a mite odd"

"forecast/weatherman" or "weather forecast/man"

"'Oh, the weather man's gotten a lot more reliable since the gummint started making it for us,' says [the noun]. 'Now he just reads off the schedule on the air every morning. Pretty much takes the fun right out of the news, if you ask me.'"

"that the weather is all generated by schedule"

"taxes/tax" or "weather tax"

"A snort. 'You'd think for the rates we pay we'd get something a little pleasanter, don't you?'"

"that the weather tax really ought to be paying for something nicer than what you get"

"job/employment/work"

"'[if the noun owns a room (called the shop)]I own [the shop],' replies [the noun][otherwise]Work at the creamery, like most folk around here,' answers [the noun]."

"this and that about employment in town"

"book/books/reading"

"'The Public Library has a good selection, excepting only the cookbook section,' says [the noun]. 'That got censored way back when-- well, way back.'"

"that the Public Library has a good collection, except for the cookbook section"

The conversation of Vanessa is the Table of Vanessa Chatter.

Table of Vanessa Chatter

topic

reply

summary

turn stamp

character

"ice cream" or "sorbet/sherbet/flavor/flavors/flavour/flavours/ice/ices"

"'The flavors are [list of flavors],' she responds promptly, without needing to draw breath."

"that the flavors are [list of flavors]"

a number

a person

After reading a command:
    while player's command includes "the":
        cut the matched text.

This strips 'the' out of the command, so that ASK PERSON ABOUT THE RAIN will be understood as well as ASK PERSON ABOUT RAIN.

Now we try something a bit unusual. Inform on its own will report each action on its own line, so that each character who walks into or out of a room will be described in a separate paragraph. This is usually fine, but in a game with a lot of characters moving around simultaneously, it can become a bit overwhelming. Instead, we may want to condense these reports into a single line, such as "Ben and Jerry enter from the south". The following accomplishes that goal by replacing some of the reporting rules, storing the information in a table, and then reading the table back later, once all the character movement has been resolved and the reports can usefully be collated:

Section 6 - Movement Description

A person has some text called walk style. The walk style of a man is usually "stride". The walk style of a woman is usually "strut". The walk style of Gene is "[one of]wander[or]stroll[purely at random]". The walk style of Francine is "waddle". The walk style of Antony is "scamper". The walk style of Rhoda is "sashay".

Table of Visible Exits

character

second

third

heading chosen

total

a person

a person

a person

a direction

a number

with 10 blank rows.

Table of Visible Entrances

character

second

third

heading chosen

total

a person

a person

a person

a direction

a number

with 10 blank rows.

To clear (current table - a table name):
    repeat through current table:
        blank out the whole row.

To tidy departures of (current table - a table name):
    let next direction be up;
    repeat through current table:
        if heading chosen entry is next direction:
            let accomplice be character entry;
            choose row with heading chosen of next direction in the current table;
            if total entry is 1:
                now second entry is accomplice;
                now total entry is 2;
            if total entry is 2:
                unless the second entry is accomplice:
                    now third entry is accomplice;
                    now total entry is 3;
            choose row with character of accomplice in the current table;
            blank out the whole row;
        otherwise:
            let next direction be heading chosen entry.

A door has a person called last opener.

Report someone opening a door:
    now group size is 1;
    now the last opener of the noun is the person asked;
    if the person asked is visible, say "[The person asked] opens [the noun]. [run paragraph on]" instead;
    otherwise say "[The noun] opens from the other side. [run paragraph on]" instead.

Report someone going through a door (called route):
    if the person asked is not the last opener of the route, continue the action;
    if the person asked is the last person named, say "[The person asked as pronoun]";
    otherwise say "[The person asked]";
    say " [if the person asked is in the location]comes[otherwise]goes[end if] through[if the last thing named is not the route] [the route][end if]." instead.

The last thing named is a thing that varies. Before printing the name of something (called target) which is not a person: now the last thing named is the target.

Report someone going a direction:
    if the person asked is in the location,
        choose a blank row in the table of visible entrances;
    otherwise choose a blank row in the table of visible exits;
    now character entry is the person asked;
    now total entry is 1;
    if the person asked is in the location,
        now heading chosen entry is the opposite of the noun;
    otherwise now heading chosen entry is the noun;
    stop the action.

This is the movement reporting rule:
    sort the Table of Visible Entrances in heading chosen order;
    tidy departures of the table of visible entrances;
    sort the Table of Visible exits in heading chosen order;
    tidy departures of the table of visible exits;
    let total row count be the number of filled rows in the Table of Visible Entrances plus the number of filled rows in the Table of Visible Exits;
    if total row count is 0, rule succeeds;
    generate descriptions from the Table of Visible Entrances;
    generate descriptions from the Table of Visible Exits;
    clear the Table of Visible Entrances; clear the Table of Visible Exits.

To generate descriptions from (current table - a table name):
    let count be the number of filled rows in the current table;
    if count is 0, rule succeeds;
    let index be count;
    repeat through the current table:
        let accomplice be character entry;
        if character entry is a person, now character entry is marked for listing;
        if there is a second entry and second entry is a person, now second entry is marked for listing;
        if there is a third entry and third entry is a person, now third entry is marked for listing;
        let target be the room the heading chosen entry from the location;
        if total entry is 3, say "[The character entry], [the second entry][optional comma] and [the third entry] ";
        if total entry is 2, say "[The character entry] and [the second entry] ";
        if total entry is 1:
            if the character entry is the last person named, say "[The character entry as pronoun] ";
            otherwise say "[The character entry] ";
        if total entry is 1, say "[walk style of the character entry]s ";
        otherwise say "walk[if total entry is 1]s[end if] ";
        if the character entry is in the location:
            if location is indoors and target is indoors, say "over from ";
            if location is outdoors and target is indoors, say "out of ";
            if location is indoors and target is outdoors, say "in from ";
            if location is outdoors and target is outdoors, say "over from ";
        otherwise:
            if location is indoors and target is indoors, say "over to ";
            if location is outdoors and target is indoors, say "into ";
            if location is indoors and target is outdoors, say "out [if a door is visible][the random visible door][end if] to ";
            if location is outdoors and target is outdoors, say "over to ";
        if target is outdoors, say "[the heading chosen entry]";
        otherwise say "[the target]";
        if the total entry is 1 and count is 1 and accomplice carries something, say ", carrying [a list of things carried by the accomplice]";
        decrement index;
        make delimiter index of count, continuing;
        now group size is total entry;
    if a marked for listing person is infected:
        [eliminate the case in which we have already seen this description because we just typed LOOK and the patient was in the room at the time]
        if looking and a marked for listing person is not in the location:
            clear marked people;
            say paragraph break;
        otherwise:
            describe patients;
    otherwise:
        clear marked people;
        say paragraph break.

The last person named is a person that varies. Before printing the name of a person (called target): now the last person named is the target. Group size is a number that varies. Group size is 1.

To clear marked people:
    repeat with named party running through people:
        now the named party is not marked for listing.

Before listing nondescript items:
    if the number of people who are marked for listing is 0, make no decision;
    say "You can see [a list of people who are marked for listing] here. ";
    now group size is the number of people who are marked for listing;
    describe patients;
    now every marked for listing person is not marked for listing.

To describe patients:
    if every marked for listing person is infected and at least three people are marked for listing:
        say "They are all sick as dogs, every one.";
        clear marked people;
        rule succeeds;
    otherwise:
        if the number of people who are marked for listing is greater than two and the number of infected people who are marked for listing is greater than the number of clean people who are marked for listing:
            say "Only [the list of clean people who are marked for listing] currently remain[if the number of clean people who are marked for listing is 1]s[end if] untainted.";
            clear marked people;
            rule succeeds;
    let count be the number of marked for listing other people who are infected;
    if count is 0:
        say paragraph break;
        make no decision;
    let index be count;
    repeat with patient running through marked for listing other people who are infected:
        if index is count:
            if count is 1 and the patient is the last person named:
                say "[The patient as pronoun]";
            otherwise:
                say "[The patient]";
        otherwise:
            say "[the patient]";
        say " [looks as though dipped in for index] [infection color of the patient]";
        decrement index;
        make delimiter index of count;
    clear marked people.

To say (named character - a man) as pronoun:
    if group size is 1, say "He"; if group size is 2, say "The latter"; if group size is greater than 2, say "The last".

To say (named character - a woman) as pronoun: if group size is 1, say "She"; if group size is 2, say "The latter"; if group size is greater than 2, say "The last".

To say looks as though dipped in for (index - a number):
    let divider be the number of filled rows in the Table of Dipping Phrases;
    if index is greater than 4, let index be the remainder after dividing index by divider;
    choose row index in the Table of Dipping Phrases;
    say dipping entry.

Table of Dipping Phrases
dipping
"looks as though dipped in"
"could have been rolling in"
"has a bad case of"
"suffers from"
"contracted a virulent"

A door is usually scenery.

The next part could be simpler, but for rigor we will write it in such a way that it will work whether or not the serial comma is in use. This requires some extra work.

To make delimiter (index - a number) of (count - a number), continuing or halting:
    if index is 0:
        if continuing, say ". [run paragraph on]";
        otherwise say ".";
    otherwise if index is 1:
        if count is 2, say " and ";
        otherwise say "[optional comma] and ";
    otherwise:
        say ", ".

To say optional comma:
    if the serial comma option is active:
        say ",".

Test me with "go to cold comfort / z / z / z / z / ask vanessa for french vanilla / ask vanessa for chocolate / ask vanessa about flavors / ask vanessa for chocolate chocolate chip".

Because so much of this game is randomized, it will not be possible to provide a test command that systematically solves it. A good strategy is to go to Main Street, get the syringe; go to the Town Hall and get the key; then visit the shops, inject everyone, and lock them in when they've all been injected. Then go to the Pool Hall, turn on the air conditioner, and wait for the remaining parties to show up.

This is also something that could get fairly slow if we added many more rooms and characters to it. In that case, we might want to select fast route-finding so that character movement won't take as long. This will cost memory, possibly forcing the game into Glulx format if it isn't already, but significantly reduce the run-time for large maps with numerous people moving each turn:

paste.png Use fast route-finding.

RB §7.14. Obedient Characters

Other characters can perform all the same activities that the player can; this does not always mean that they're willing to obey the player's instructions. By default, characters will refuse to obey commands of the form JULIA, WEST or ANTONY, TAKE THE PINCUSHION. Their objections can be overridden, however, and The Hypnotist of Blois implements a hypnotist who can make characters obedient at will.

In For Demonstration Purposes ★★★, the character is only capable of a few actions at the outset, but can be taught new ones if the player performs them first.

Often we want characters' obedience to be more selective. Just as the viewpoint character may be characterized in terms of what he will and will not do, so may others: Generation X ★★ demonstrates a character who will do what she's told, but who will comment unfavorably when the player asks for a nonsensical or repeated action, and who may eventually get fed up and leave.

Characters can be given moral objections to certain commands, as well: Virtue defines a few kinds of actions as bad, so that the character commanded will refuse to perform them.

Under Contract ★★★★, more subtly, has the character object if the player's commands implicitly require any behavior he considers inappropriate: for instance, if the player commands him to put his pants in a container, he will work out that this requires the removal of the pants as a preliminary. If we want to implement a similar character, we may want to simply copy his unsuccessful attempt rule and the table of his retorts, then replace his banter with lines of our choosing.

The little example Latin Lessons allows us to make characters clever about vague commands: we can, for instance, write rules so that CLARK, EAT will have Clark sensibly pick something edible, rather than having the parser ask what we want Clark to eat.

Finally, Northstar ★★ demonstrates how we might make Inform understand commands of the form ASK JOSH TO TAKE INVENTORY or ORDER JOAN TO WEAR THE ARMOR.

See also

Characters Following a Script for a programmable robot who can be given whole sequences of actions to perform

Examples

184. Virtue

paste.png "Virtue"

The Cloister is a room. Lady Teresa is a woman in the Cloister. Mother Margaret is a woman in the Cloister.

Attacking someone is misbehavior. Kissing someone is misbehavior.

Instead of asking someone to try misbehavior: say "[The person asked] stiffens, offended by your suggestion."

Test me with "kiss margaret / margaret, kiss me".

186. The Hypnotist of Blois

paste.png "The Hypnotist of Blois"

A person is either hypnotized or alert. A person is usually alert.

Persuasion rule for asking a hypnotized person to try doing something:
    persuasion succeeds.

Understand "hypnotize [someone]" as hypnotizing.

Hypnotizing is an action applying to one thing.

Check hypnotizing:
    if the noun is hypnotized, say "Already done." instead.

Carry out hypnotizing:
    now the noun is hypnotized.

Report hypnotizing:
    say "[The noun] slips under your control."

Instead of waking someone hypnotized:
    now the noun is alert;
    say "[The noun] returns abruptly to consciousness."

We will learn more about check rules for other characters shortly, but the following prevents the hypnosis patient from trying to hypnotize us in turn:

Check someone hypnotizing someone:
    stop the action.

Maison de la Magie is a room. "In a darkened room, a few hundreds of paces from the chateau of Blois, you give to tourists three shows a day: displaying to them power they do not comprehend and spectacles they do not deserve."

A volunteer is a woman in the Maison. "A volunteer from the audience stands facing you, [if alert]skeptically awaiting hypnosis[otherwise]her face worshipful and obedient[end if]." The printed name of the volunteer is "volunteer from the audience". The description is "A distracted, susceptible woman." The volunteer wears a t-shirt and a baseball hat.

The player wears a top hat and a cape.

Test me with "volunteer, remove hat / hypnotize volunteer / look / volunteer, remove hat / wake volunteer / volunteer, wear hat".

371. Latin Lessons

If we're defining actions for other characters to follow, we may want to include them in our "rule for supplying a missing noun". We can do this if we write our "while..." clause to apply to any actor, as follows:

paste.png "Latin Lessons"

The Latin Studio is a room. Rick is a man in the Studio.

A dance-name is a kind of thing. Argentine tango, samba, merengue, cha-cha, street salsa are dance-names.

Dancing is an action applying to one visible thing. Understand "dance [any dance-name]" as dancing. Understand "dance" as dancing.

Rule for supplying a missing noun while an actor dancing:
    now the noun is street salsa.

Report someone dancing:
    say "[The actor] dances a few steps of [the noun] for you."

Report dancing:
    say "You dance a few steps of [the noun]."

Persuasion rule for asking someone to try dancing: persuasion succeeds.

Test me with "dance / dance samba / rick, dance / rick, dance merengue".

188. Generation X ★★

paste.png "Generation X"

The Volunteer Center is a room. "A fairly spartan office, though there are a few attractive posters from advertising campaigns of the past, and an ominous map charting the deforestation of Brazil."

The desk is scenery in the Volunteer Center. "Your standard metal desk, with a drawer for postal supplies and the like." On the desk is a pile of leaflets and a pile of business cards. The power stapler is a device on the desk. A drawer is part of the desk. It is openable and closed. In the drawer are a sponge and a roll of bulk-mail stamps.

Instead of doing something:
    if examining, continue the action;
    if searching, continue the action;
    if looking, continue the action;
    if asking Jenna to try doing something, continue the action;
    say "The whole point of this exercise is to train Jenna. Once you have her on the envelope-stuffing, you can go make some calls."

Instead of answering Jenna that something:
    say "You're going to have to break the instructions down to the simplest ones possible, given that she's in the mood to misunderstand on purpose."

A cardboard box is in the Center. In the cardboard box is a pile of empty envelopes. The box is openable and closed. The description is "A recycling symbol is prominent on the side, which makes you feel a little bit better about using a mailing campaign for this cause."

Jenna is a woman in the Volunteer Center. "Your daughter Jenna is here, barely visible through the cloud of resentment." The description is "Jenna [if jenna carries something]has [the list of things carried by Jenna][otherwise]returns your stare, with added hostility[end if]."

A persuasion rule for asking Jenna to try doing something: persuasion succeeds.

Unsuccessful attempt by Jenna doing something:
    repeat through Table of Retorts:
        if the reason the action failed is the cause entry:
            say "[response entry][paragraph break]";
            rule succeeds;
    say "'I don't see how I'm supposed to do that, Mom,' Jenna says."

Table of Retorts

cause

response

can't take yourself rule

"'Is that like 'get a grip on yourself' or something?' Jenna asks, momentarily diverted."

can't take what's fixed in place rule

"[physical impossibility]"

can't take scenery rule

"[physical impossibility]"

can't take what's already taken rule

"[already done]"

can't drop what's already dropped rule

"[already done]"

can't wear what's already worn rule

"[already done]"

can't take off what's not worn rule

"[already done]"

can't close what's already closed rule

"[already done]"

can't open what's already open rule

"[already done]"

can't switch off what's already off rule

"[already done]"

can't switch on what's already on rule

"[already done]"

can't unlock what's already unlocked rule

"[already done]"

can't lock what's already locked rule

"[already done]"

To say physical impossibility:
    say "'Maybe you should've brought someone a little stronger,' Jenna says. 'Like the Incredible Hulk.' "

To say already done:
    repeat through Table of Bored Remarks:
        say "[response entry]";
        blank out the whole row;
        rule succeeds;
    say "'Okay, I'm going to be, like, in the car,' says Jenna. 'Outside.' ";
    end the story saying "Jenna has gotten fed up".

Table of Bored Remarks
response
"'Did that,' says Jenna."
"'Check,' says Jenna."
"'Yeah, Mom, I already did that, okay?'"
"'Look, if I have to be here doing dumb stuff, could you at least tell me to do stuff that isn't already done?' Jenna asks wearily."
"Jenna gives a great upward sigh, riffling her bangs. 'Once again... there is totally no point.'"

Test me with "e / x jenna / jenna, get stapler / jenna, get stapler / x jenna / jenna, drop stapler / jenna, drop stapler / jenna, open box / jenna, open box / jenna, switch stapler on / jenna, switch stapler on / jenna, take desk / jenna, open box / jenna, open box".

422. Northstar ★★

Most of the time, Inform understands commands to other characters when they take the form "JOSH, TAKE INVENTORY" or "JOAN, WEAR THE ARMOR". But novice players might also try commands of the form ASK JOSH TO TAKE INVENTORY or ORDER JOAN TO WEAR THE ARMOR.

The easiest way to make Inform understand such commands is to meddle directly with the player's command, changing it into the format that the game will understand, as here:

paste.png "Northstar"

The Northstar Cafe is a room. "The Northstar is crammed with its usual brunch crowd, and you were lucky to get a table at all. You are now awaiting the arrival of your ricotta pancakes."

Josh is a man in The Northstar Cafe. "Josh is on his way past your table." The description of Josh is "He is a waiter here, but you also know him socially, so he tends to be more chatty than the other waiters." A persuasion rule: persuasion succeeds.

After reading a command:
    let N be "[the player's command]";
    replace the regular expression "\b(ask|tell|order) (.+?) to (.+)" in N with "\2, \3";
    change the text of the player's command to N.

Test me with "ask Josh to take inventory / tell Josh to take inventory / order Josh to take inventory".

Note that we have to copy N back explicitly to replace the player's command.

239. For Demonstration Purposes ★★★

Suppose we want to have a character who can dynamically learn new actions by observing the player performing them. We could do this by adding the actions to a list of things the character can do, but using a relation to express the same idea allows for tidier, easier-to-read code.

Thanks to Jesse McGrew for the initial design of this example.

paste.png "For Demonstration Purposes"

Section 1 - Procedure

Capability relates various people to various stored actions. The verb to be capable of means the capability relation.

Persuasion rule:
    let CA be the current action with no specific actor;
    if the person asked is capable of CA:
        persuasion succeeds;
    otherwise:
        say "[The person asked] look[s] confused. Maybe a demonstration would help.";
        persuasion fails.

The action requester is an object that varies. The action requester variable translates into I6 as "act_requester".

To decide which action is the current action with no specific actor:
    let old actor be the person asked;
    let old requester be the action requester;
    now the person asked is the player;
    now the action requester is nothing;
    let CA be the current action;
    now the person asked is the old actor;
    now the action requester is the old requester;
    decide on CA.

The learning by observation rule is listed after the report stage rule in the specific action-processing rules.

Definition: a person is other if he is not the player.

This is the learning by observation rule:
    repeat with the viewer running through other people who can see the player:
        if the player is the actor and viewer is not capable of the current action:
            say "[The viewer] watches your behavior with interest. Seems like [they] [are] learning.";
            now the viewer is capable of the current action.

Section 2 - Scenario

The Daily Planet is a room. Clark is here. He is a man.

When play begins:
    now Clark is capable of taking inventory.

Test me with "Clark, inventory / Clark, x me / x me / Clark, x me".

205. Under Contract ★★★★

paste.png "Under Contract"

The Sound Stage is a room. The description is "A somewhat creaky and unconvincing reproduction of the docks of San Francisco."

Clark Gable is a man in the Sound Stage. "Clark is here, carrying [the list of things carried by Clark][if Clark wears anything] and wearing [the list of things worn by Clark][end if]." Clark carries a swagger stick. Clark carries an open openable player's holdall called a briefcase. The briefcase contains a signed contract. Clark wears a fedora and a pair of pants. A handle is part of the briefcase.

The player carries an open openable player's holdall called a frilly bag. The carrying capacity of the player is 2. The player wears a sparkly scarf and a slinky dress. A strap is part of the bag. The tent is a portable enterable container.

Instead of taking off the slinky dress: say "Rowr! Not that kind of movie, babe."

Instead of taking off the pants: say "That's not your job, whatever the society pages might suggest."

Unsuccessful attempt by Clark doing something:
    repeat through table of Clark Retorts:
        if the reason the action failed is the cause entry:
            say "[response entry][paragraph break]";
            rule succeeds;
    say "'I don't think that's in the script,' says Clark dubiously."

Table of Clark Retorts

cause

response

can't take yourself rule

"'I'm always self-possessed,' Clark remarks. You've heard that line before, but it sounds so much more convincing from him."

can't take other people rule

"'I don't think it would be appreciated if I tried to do that to [the noun],' he rumbles."

can't take component parts rule

"'I don't want to rip [the noun] out,' Clark remarks."

can't take people's possessions rule

"'I don't cotton to acting like a thief,' Clark replies. 'It ain't proper.'"

can't take what you're inside rule

"'Do you see where I am, babe?' Clark demands."

can't take what's already taken rule

"[already done]"

can't take scenery rule

"'I'm not the stunt man, darling,' he says with a wry twinkle."

can't take what's fixed in place rule

"'I'm not the stunt man, darling,' he says with a wry twinkle."

can't exceed carrying capacity rule

"Clark grins. 'I've only got so many hands, darling,' he says."

can't insert into closed containers rule

"[physical impossibility]"

can't go that way rule

"[physical impossibility]"

can't go through closed doors rule

"[physical impossibility]"

can't enter closed containers rule

"[physical impossibility]"

can't exit closed containers rule

"[physical impossibility]"

can't drop yourself rule

"'We're inseparable, me and me,' Clark replies, with a smile."

can't drop what's already dropped rule

"[already done]"

can't drop what's not held rule

"'Not under my control, [the noun],' replies Clark."

can't drop clothes being worn rule

"[salacious retort]"

can't put something on itself rule

"'I lack the dexterity,' says Clark. Oh, he's so modest."

can't put onto what's not a supporter rule

"'[The second noun] won't support a thing,' says Clark reprovingly."

can't put clothes being worn rule

"[salacious retort]"

can't insert clothes being worn rule

"[salacious retort]"

can't give worn items rule

"[salacious retort]"

can't wear what's not clothing rule

"'Costuming just gets stranger every year,' says Clark. 'In short: no.'"

can't wear what's already worn rule

"[already done]"

can't eat unless edible rule

"'What're you trying to do, poison me?'"

can't eat clothing without removing it first rule

"[salacious retort]"

can't take off what's not worn rule

"[already done]"

can't close what's already closed rule

"[already done]"

can't open what's already open rule

"[already done]"

can't switch off what's already off rule

"[already done]"

can't switch on what's already on rule

"[already done]"

can't unlock what's already unlocked rule

"[already done]"

can't lock what's already locked rule

"[already done]"

To say already done:
    repeat through Table of Clark's Bored Remarks:
        say "[response entry]";
        blank out the whole row;
        rule succeeds;
    say "'Already done.' "

Table of Clark's Bored Remarks
response
"'I have anticipated your every demand.'"
"'We've been through this part of the script already,' Clark remarks, with just a hint of creeping tedium."
"'Right right, already taken care of...'"
"'I'm a believer in rehearsal,' Clark says, sounding more bored than ever, 'but we really have got all this done already.'"

To say salacious retort:
    repeat through Table of Clark's Flirtatious Remarks:
        say "[response entry]";
        blank out the whole row;
        rule succeeds;
    say "Clark, driven past the point of endurance, seizes you in his arms and kisses you.";
    end the story finally.

Table of Clark's Flirtatious Remarks
response
"Clark allows his mustache to quirk at the suggestion."
"Clark wiggles his eyebrows at you."
"'That kind of thing isn't in my contract, sweetie,' says Clark. 'If you're interested you'll have to ask off-camera.'"
"'I'd feel so... bare,' Clark says, with a sidelong look at you."
"'You first,' says Clark."
"Clark's stare is intense. You may be on the verge of breaking him."

To say physical impossibility:
    repeat through Table of Clark's Frustrated Denials:
        say "[response entry]";
        blank out the whole row;
        rule succeeds;
    say "Clark makes a helpless gesture about his ability to move himself, or parts of himself, through solid objects. "

Table of Clark's Frustrated Denials
response
"Clark frowns. 'I can't reach through things -- unless you were planning a special effect?'"
"'Look,' says Clark. 'If you want a stage magician, hire one.'"
"Clark just groans."
"Clark says drily, 'Is this in the script, or are we doing improvisation now?'"

The block giving rule is not listed in the check giving it to rules. The block showing rule is not listed in the check showing it to rules. The report smelling rule is not listed in the report smelling rules. The report listening rule is not listed in the report listening to rules.

Carry out listening to something:
    do nothing.

Report listening to something: say "Your attention bears no interesting result."

Carry out smelling something:
    do nothing.

Report smelling something: say "Your attention bears no interesting result."

Report someone listening to something: say "[The person asked] concentrates, listening."

Report someone smelling something: say "[The person asked] sniffs at [the noun]."

Instead of asking someone for something: try asking the noun to try giving the second noun to the player.

Carry out showing something to someone: say "You reveal [the noun] to [the second noun]."

Carry out Clark showing something to someone:
    if the second noun is the player:
        say "Clark shows you [the noun]. [run paragraph on]";
        try examining the noun;
    otherwise:
        say "Clark reveals [the noun] to [the second noun]."

Instead of asking someone to try saying yes: try saying yes. Instead of asking someone to try saying no: try saying no. Instead of asking someone to try saying sorry, try saying sorry.

And now we make Clark a very amenable type:

A persuasion rule for asking people to try doing something: persuasion succeeds.

There are quite a few actions for which no automatic other-character behavior is provided at all, because they always end in failure when the player tries them. Currently the response is not very interesting. Let's spice it up a bit:

Burning something is useless action. Waking up is useless action. Thinking is useless action. Cutting is useless action. Jumping is useless action. Tying something to something is useless action. Drinking something is useless action. Swinging is useless action. Rubbing is useless action. Setting something to something is useless action. Waving hands is useless action. Buying is useless action. Climbing is useless action. Sleeping is useless action. Kissing is useless action. Throwing something at something is useless action. Attacking is useless action. Asking something about something is useless action. Telling something about something is useless action. Answering something that something is useless action. Waking something is useless action.

A persuasion rule for asking people to try useless action:
    say "Clark Gable frowns. 'I don't mean to be difficult, but I can't see any point in that.'";
    persuasion fails.

A persuasion rule for asking Clark to try taking off the pants:
    say "He gives you a look of mocking exasperation. Apparently you'll have to take a (slightly) more subtle approach.";
    persuasion fails.

    Check someone giving something to someone (this is the can't give worn items rule):
        if the person asked wears the noun, stop the action.

And because we do not want Clark automatically taking off the pants as the result of a drop action:

Instead of Clark taking off the pants: do nothing.

We know that this can only come about as a default action, because we have arranged matters so that he cannot be persuaded directly.

Test me with "give dress to clark / clark, take off pants / clark, eat pants / clark, give me the pants / clark, drop pants / clark, put the pants in the briefcase / again / g / g / g"

RB §7.15. Goal-Seeking Characters

Goal-seeking characters are the most advanced IF life-form: they want to achieve specific outcomes, and they are able to work out plans of approach in order to bring these things about. They walk to rooms, open containers to search for things, use keys and tools, and ask leading questions in conversation.

A really advanced implementation of goal-seeking behavior is beyond the scope of our examples (though extensions exist that treat the problem more thoroughly). We can accomplish a surprising amount without heavy customization, though, if we keep in mind three points of technique:

First: it helps to think abstractly and to create broadly-defined actions as a first step to more specific tasks. For instance, a character's goal might be to eat some dinner. He'd be equally satisfied with spaghetti carbonara or with braised lamb shanks, but he needs to figure out which is available. So we might have our every turn rule (or whatever we're using to activate the character) say something like

Every turn when Clark is hungry:
    try Clark dining.

Dining would then be an action we've defined specially, which looks around Clark's environment for suitable food; if it finds food, it issues a

try Clark eating the suitable food;

command; but if not, it sends Clark off to look for something likely. The Man of Steel ★★ demonstrates the use of this.

Second: though it doesn't actually contribute to the goal-seeking per se, lively reporting brings characters' generated behavior to life.

Clark eats a donut.

doesn't characterize Clark very much, even though the eating may be part of a subtle, intelligent plan to seduce Lois Lane. We'll do better if we replace a lot of the character reporting rules: to that end, see the example The Man of Steel Excuses Himself ★★.

Third: goal-seeking characters notice when something is in the way of the action they want to perform. When that happens, they form a plan about how to remove the obstacle. We've already seen this kind of implementation on the player's behalf: the player will pick up items before eating them, say. We can use Before rules to do similar things for other characters, as in

Before Clark eating the wrapped candy:
    try Clark unwrapping the candy;
    if the candy is wrapped, stop the action.

Here we've set things up so that if Clark tries to eat the wrapped candy, he'll be interrupted by this other command; and if his unwrapping-the-candy attempt fails, he won't go on and eat the thing. IQ Test demonstrates a character who shows this kind of planning intelligence.

Because before-rules chain neatly, we can trigger whole plans of behavior if we have a sensible set, as in

Before someone entering a closed container: try the person asked opening the noun.
Before someone opening a locked container: try the person asked unlocking the noun.
Before someone unlocking a locked container: ...

We must exercise a little bit of care if it is possible for the chain of actions to produce an endless loop - e.g., the character trying to take a key that is inside the transparent, locked box that it opens might repeatedly try to open the box, first unlocking the box, first taking the key, first opening the box, ... Boston Cream ★★★★ is a fully-worked scenario that deals with such a set of conundra.

See also

Traveling Characters for characters who plan routes to locations and travel towards them
Event Scheduling for characters who follow a pre-written schedule of activities
Plot Management for having a central function direct all the characters in order to further the plot

Examples

189. IQ Test

We have already seen how Before... rules can generate implicit actions for the player, so that the player will, for instance, open doors before trying to walk through them. The same can be done for characters other than the player; so for instance:

paste.png "IQ Test"

The Donut Shop is a room. "Vibrantly decorated in donut colors: pink, brown, and cream."

Ogg is a man in the Donut Shop. "Ogg is slumped in the corner[if Ogg carries something] with [a list of things carried by Ogg][end if]. He wears a nametag which says 'HELLO MY NAME IS OG.'" Understand "og" as Ogg. Ogg wears a nametag. The description of the nametag is "Sadly misspelled."

The Donut Shop contains a transparent closed openable locked lockable container called a case. The case contains some cake donuts. The donuts are edible.

The matching key of the case is a silver key. The silver key is carried by Ogg.

A persuasion rule for asking someone to try doing something:
    persuasion succeeds.

Before someone opening a locked thing (called the sealed chest):
    if the person asked is carrying the matching key of the sealed chest, try the person asked unlocking the sealed chest with the matching key of the sealed chest;
    if the sealed chest is locked, stop the action.

Before someone taking something which is in a closed container (called the shut chest):
    try the person asked opening the shut chest;
    if the shut chest is closed, stop the action.

The block giving rule is not listed in the check giving it to rules.

Test me with "open case / get donuts / og, get donuts / og, give me the donuts / eat donuts".

(A more detailed set of before rules for people using doors and locks is provided in Emily Short's Locksmith extension.)

203. The Man of Steel ★★

It will sometimes be handy to write actions that are only available to the non-player characters and not to the player. To do this, we just define an action which has no "understand": the player will never be able to specify this command himself, but other characters can try it.

This is particularly useful for creating abstract or general actions for when we want a character to eat something, wear something, or go somewhere, but aren't too particular as to what the object is; as here, where we just want Clark to move away from the kryptonite, regardless of direction:

paste.png "The Man of Steel"

Escaping is an action applying to nothing.

Carry out someone escaping:
    let space be the holder of the person asked;
    let place be a random room which is adjacent to the space;
    let way be the best route from the space to the place;
    try the person asked going way.

Every turn:
    if Clark Kent can see kryptonite, try Clark Kent escaping.

The Daily Planet Newsroom is a room.

Perry White's Office is west of the Newsroom. In Perry White's Office are a desk and a poster of Elvis. On the desk is a lead-lined box. The box is openable. In the box is the green kryptonite crystal.

The Supply Closet is east of the Newsroom. The Elevator Bank is north of the Newsroom.

Clark Kent is a man in the Newsroom. "Clark [if Clark can see the kryptonite]looks a bit ill[otherwise]is here, frowning as he revises his latest article[end if]."

Test me with "west / get box / east / close box / east / west / north / south / west".

208. The Man of Steel Excuses Himself ★★

Report rules can be a good point at which to add local color: while Inform provides default descriptions of character behavior, these are rather generic and can stand to be customized.

For instance, if we wanted to liven up our previous Clark Kent example:

paste.png Report Clark Kent going a direction (called the way):
    say "[one of]With a particularly weak excuse[or]Muttering[at random] about [random excuse subject], Clark heads [way]." instead.

To say random excuse subject:
    choose a random row in the Table of Lame Excuses; say "[reply entry]".

Table of Lame Excuses
reply
"needing a paper-clip"
"wanting an English-Tuvalu dictionary"
"walking a neighbor's dog"
"hearing air-raid sirens"
"having drunk too much coffee"
"thinking he smells smoke"
"wondering where Lois got to"
"needing to speak to Jimmy"
"noticing the Good Year blimp"

It's good to be careful, as the library report rules have been designed and tested to describe every contingency (going through doors, going in vehicles, etc.): so when replacing a report rule, we should try to consider all the possible variations of the action that we might want to describe.

However, in this case, our scenario is so simple that there are no doors, vehicles, or pushable objects, so we're safe in giving Clark a very simple reporting scheme.

190. Boston Cream ★★★★

paste.png "Boston Cream"

Use scoring.

The Donut Shop is a room. "Vibrantly decorated in donut colors: pink, brown, and cream."

Ogg is a man in the Donut Shop. "Ogg is slumped in the corner[if Ogg carries something] with [a list of things carried by Ogg][end if]. He wears a nametag which says 'HELLO MY NAME IS OG.'" Understand "og" as Ogg. Ogg wears a nametag. The description of the nametag is "Very neatly written."

The Donut Shop contains a transparent closed openable locked lockable enterable container called a case. The case is fixed in place. The case contains some cake donuts, some jelly donuts, and some apple fritters. "The [if unopenable]damaged[otherwise]gleaming[end if] donut case [if something is in the case]contains [a list of things in the case][otherwise]has been stripped of its contents[end if]." The cake donuts, the jelly donuts, and the apple fritters are edible.

The matching key of the case is a silver key. The silver key is in a mesh basket. The mesh basket is closed, transparent, and openable. It is in the Donut Shop.

Before someone taking something which is carried by the player:
    if the person asked cannot touch the player:
        say "Ogg looks with a fixed frown at [the noun].";
        continue the action;
    say "[The person asked] comes up and shakes your arm until you drop [the noun].";
    say line break;
    silently try dropping the noun;
    stop the action.

Before someone unlocking a locked thing with something which is not carried by the person asked:
    try the person asked taking the second noun;
    stop the action.

Before someone opening a locked thing (called the sealed chest):
    if the person asked can see the matching key of the sealed chest:
        if the matching key of the sealed chest is enclosed by the sealed chest:
            say "Seeing the paradoxical location of [the matching key of the sealed chest], [the person asked] gives a howl of rage.";
            increment the score;
            end the story finally saying "You have thwarted Ogg";
        otherwise:
            try the person asked unlocking the sealed chest with the matching key of the sealed chest;
        stop the action.

Before someone taking something which is in a closed container (called the shut chest):
    try the person asked opening the shut chest;
    stop the action.

Ogg has a number called hunger. The hunger of Ogg is 0.

Every turn:
    increment the hunger of Ogg;
    if the hunger of Ogg is 2 and Ogg is visible, say "Ogg's stomach growls.";
    if the hunger of Ogg is 3 and Ogg is visible:
        if Ogg can see an edible thing (called the target):
            say "Ogg eyes [the target] with obvious intent.";
        otherwise:
            say "Ogg glances at you in a disturbingly shifty way.";
    if the hunger of Ogg is greater than 3:
        if Ogg carries an edible thing (called the target):
            try Ogg eating the target;
        otherwise:
            let new target be a random edible thing which can be seen by Ogg;
            if the new target is a thing:
                try Ogg taking the new target;
            otherwise:
                if Ogg can touch the player, end the story saying "Ogg is gnawing your ankle";
                otherwise try Ogg taking the player.

The crumbs are a thing. "Crumbs of [the list of edible things which cannot be seen by the player] lie scattered over the whole floor."

Instead of asking Ogg to try doing something when Ogg cannot touch the player:
    say "Ogg tilts his head and shrugs, unable to hear your instruction clearly."

Instead of asking Ogg to try eating something:
    say "It's not as though Ogg really needs any encouragement in that department, is it?"

Definition: Ogg is hungry if the hunger of Ogg is greater than 2.

Persuasion rule for asking Ogg to try doing something: if Ogg is hungry, persuasion fails; persuasion succeeds.

Persuasion rule for asking Ogg to try giving something edible to the player:
    persuasion fails.

Unsuccessful attempt by Ogg doing something:
    if the reason the action failed is a failing listed in the Table of Ogg Retorts:
        say "[reply entry][paragraph break]";
    otherwise:
        say "Ogg looks adorably confused."

Table of Ogg Retorts

failing

reply

can't take people's possessions rule

"'Ogg too polite.'"

can't take other people rule

"'Ogg not that greedy.'"

can't take scenery rule

"'[The noun] very very heavy.'"

can't take what's fixed in place rule

"'[The noun] very heavy."

can't drop what's not held rule

"'Hunh?'"

Carry out Ogg eating an edible thing:
    move the crumbs to the holder of Ogg;
    now the hunger of Ogg is 0.

Report Ogg unlocking something with something:
    say "Ogg struggles a bit with [the second noun] in the lock of [the noun], but does eventually succeed. 'Hunh!' says Ogg.";
    stop the action.

Carry out Ogg opening the case when the case has been open:
    now the case is unopenable.

Instead of closing the unopenable case:
    say "The glass panels are no longer properly seated in their tracks, and the case cannot be closed ever again."

Report Ogg opening the unopenable case:
    say "Ogg forces [the case] so hard that it does break.";
    stop the action.

Report Ogg opening the case:
    say "Ogg yanks [the noun] open with such force that you fear for its structural integrity.";
    stop the action.

Report Ogg taking something edible:
    say "Ogg acquires [the noun] with a look of tender affection.";
    stop the action.

Report Ogg eating something:
    say "Ogg chows down on [the noun], scattering crumbs in all directions.";
    stop the action.

Report Ogg eating something when the number of visible edible things is 1:
    say "Ogg eats [the noun] in his trademark style. You can no longer bear to watch.";
    stop the action.

After entering the case:
    say "You climb inside the case, folding yourself up uncomfortably."

After locking the case with something when the player is in the case:
    say "You turn the key firmly in the lock -- amazing it locks from within, but it does -- and settle yourself for a long wait, hoping this thing is not air-tight."

The maximum score is 1.

Test me with "open mesh / get key / unlock case / open case / enter case / close case / lock case / wait / wait".

RB §7.16. Social Groups

Crowds of characters introduce new challenges, because we often want to show them interacting with one another, or to describe individuals in less detail when a whole group is present.

Strictly Ballroom ★★ gives us a set of characters who pair off each turn, making sure to mention each one once, and leaving one unfortunate person behind as a wallflower: this exemplifies how we might use a behavioral rule not to dictate the behavior of each individual separately but rather to model a whole group together. Happy Hour ★★ does calculate movements for characters individually, but then collates the descriptions, creating a single paragraph to describe whatever group is currently in the room.

Characters can also have complicated attitudes to one another, and it can be helpful to use relations to track these. Unthinkable Alliances demonstrates the grouping of characters into alliance factions, while The Abolition of Love provides a host of relations to track love affairs, marriages, memberships in families, and mere mutual respect.

Emma ★★ combines these two effects: its characters move between social groups depending on how they feel about the others in their particular talking circle, and descriptions change depending on who is where in the room.

Lugubrious Pete's Delicatessen simulates a queue at a deli, in which the customers who most impress Pete get served first.

See also

Traveling Characters for groups of characters who move around and have their movements collated into a joint description

Examples

229. Unthinkable Alliances

The following is best tested by experimentally kissing and/or attacking, and typing RELATIONS after every change to see the effect.

paste.png "Unthinkable Alliances"

Unthinkable Solutions is a room. Sophie, Daisy, Ryan and Owen are in Unthinkable Solutions.

Alliance relates people to each other in groups. The verb to help means the alliance relation.

Sophie helps Ryan. Daisy helps Ryan. Owen helps the player.

Instead of kissing someone (called the blessed one):
    say "Smack!";
    now the player helps the blessed one.

Instead of attacking someone (called the vilified one):
    say "Smack!";
    now the player does not help the vilified one.

Test me with "relations / kiss sophie / relations / hit ryan / relations".

232. The Abolition of Love

Suppose we are modeling a complex society seething with interpersonal relations of every kind.

paste.png "The Abolition of Love"

Section 1 - Relation types

Loving relates one person to one person.

Noticing relates various people to one person.

Impressing relates one person to various people.

Fancying relates various people to various people.

Acquaintance relates people to each other.

Marriage relates one person to another.

Alliance relates people to each other in groups.

The Chapel is a room. Elizabeth, Wickham and Darcy are people in the Chapel. Mr Bennett and Mrs Bennett are people in the Chapel. Georgiana is a person in the Chapel.

The verb to love means the loving relation.

The verb to notice means the noticing relation.

The verb to impress means the impressing relation.

The verb to fancy means the fancying relation.

The verb to know means the acquaintance relation.

The verb to be married to means the marriage relation.

The verb to be related to means the alliance relation.

Elizabeth loves Darcy. Elizabeth fancies Darcy. Elizabeth notices Darcy. Elizabeth impresses Darcy.

Mr Bennett is related to Mrs Bennett and Elizabeth. Mr Bennett is married to Mrs Bennett.

Georgiana is related to Darcy.

Now we want ways to set and unset all of these relations. (In the interests of thoroughness, we may get a bit far-fetched here. It is not recommended in practice that we make the player guess the verb "traduce".)

Section 2 - Setting and Unsetting Love (1-1)

Understand "infatuate [someone] with [someone]" as infatuating it with. Infatuating it with is an action applying to two visible things.

Carry out infatuating it with:
    now the noun loves the second noun.

Report infatuating it with:
    say "Now [the noun] loves [a random person loved by the noun][if the second noun loves someone], while [the second noun] loves [a random person loved by the second noun][end if]."

Understand "embitter [someone] toward [someone]" as embittering it toward. Embittering it toward is an action applying to two visible things.

Carry out embittering it toward:
    now the noun does not love the second noun.

Report embittering it toward:
    say "[The noun] sees [the second noun] in a different light and no longer feels any affection."

Because love is a 1-1 relation, a person cannot love more than one other character at a time. Whenever we set a character to love a new person, that person ceases to love the character loved before. It is a fickle world.

One to various relations are a bit more open: we can say someone impresses multiple other characters, and our additions to the list do not override the initial ones.

Section 3 - Setting and Unsetting Impressed (1-V)

Understand "commend [someone] to [someone]" as commending it to. Commending it to is an action applying to two visible things.

Carry out commending it to:
    now the noun impresses the second noun.

Report commending it to:
    say "[The second noun] takes a very decided interest in [the noun]."

Understand "traduce [someone] to [someone]" as traducing it to. Traducing it to is an action applying to two visible things.

Carry out traducing it to:
    now the noun does not impress the second noun.

Report traducing it to:
    say "[The second noun], hearing your story, decides not to be at all impressed with [the noun]."

And because this is a one-to-various relation, we can also make statements which set multiple relations at once, so:

Understand "celebrate [someone]" as celebrating. Celebrating is an action applying to one visible thing.

Carry out celebrating:
    now the noun impresses every person.

Report celebrating:
    say "[The list of people who are impressed by the noun] take a very decided interest in [the noun]."

Understand "slander [someone]" as slandering to. Slandering to is an action applying to one visible thing.

Carry out slandering to:
    now every person is not impressed by the noun.

Report slandering to:
    say "Now [the noun] impresses [the list of people who are impressed by the noun]."

Note that the above unsetting is not equivalent to "now the noun does not impress every person" -- which would be ambiguous in spoken English, as well. Various-to-one relations are similar:

Section 4 - Setting and Unsetting Noticing (V-1)

Understand "draw the attention of [someone] to [someone]" as drawing the attention of it to. Drawing the attention of it to is an action applying to two visible things.

Carry out drawing the attention of it to:
    now the noun notices the second noun.

Report drawing the attention of it to:
    say "[The noun] glances thoughtfully in the direction of [the second noun]."

Understand "distract [someone] from [someone]" as distracting it from. Distracting it from is an action applying to two visible things.

Carry out distracting it from:
    now the noun does not notice the second noun.

Report distracting it from:
    say "You distract [the noun] from [the second noun]."

Understand "draw attention to [someone]" as drawing attention to. Drawing attention to is an action applying to one visible thing.

Carry out drawing attention to:
    now every person notices the noun.

Report drawing attention to:
    say "You quickly cause everyone to attend to [the noun]."

Understand "outshine [someone]" as outshining. Outshining is an action applying to one visible thing.

Carry out outshining:
    now every person does not notice the noun.

Report outshining:
    say "You quickly distract everyone from [the noun]."

Section 5 - Setting and Unsetting Fancying (V-V)

Understand "flatter [someone]" as flattering. Flattering is an action applying to one thing.

Carry out flattering:
    now every person fancies the noun.

Report flattering:
    say "You draw down universal admiration for [the noun] by casting him or her in a flattering light."

Understand "unflatter [someone]" as unflattering. [Okay, okay, but it's four am.] Unflattering is an action applying to one thing.

Carry out unflattering:
    now every person does not fancy the noun.

Report unflattering:
    say "[The noun] gives everyone a universal disgust."

Understand "admire [someone]" as admiring. Admiring is an action applying to one thing.

Carry out admiring: now the player fancies the noun.

Report admiring: say "You find you rather fancy [the noun]."

Understand "loathe [someone]" as loathing. Loathing is an action applying to one thing.

Carry out loathing: now the player does not fancy the noun.

Report loathing: say "You take [the noun] in disgust."

Understand "cause chaos" as causing chaos. Causing chaos is an action applying to nothing.

Carry out causing chaos:
    now every person fancies every person.

Report causing chaos: say "Now everyone fancies everyone else, which is quite an inconvenient state of affairs."

Understand "relieve chaos" as relieving chaos. Relieving chaos is an action applying to nothing.

Carry out relieving chaos:
    now every person is fancied by no one.

Report relieving chaos: say "Now no one fancies anyone, which is safe but tedious."

Our options for setting and unsetting symmetrical relations are more limited again:

Section 6 - Setting and Unsetting Marriage (1-1 Symmetrical)

Understand "marry [someone] to [someone]" as uniting it in matrimony with. Uniting it in matrimony with is an action applying to two visible things.

Carry out uniting it in matrimony with:
    now the noun is married to the second noun.

Report uniting it in matrimony with:
    say "You perform the marriage of [the noun] to [the second noun], joining them to the family of [a list of people related to the noun]."

Understand "divorce [someone] from [someone]" as divorcing it from. Divorcing it from is an action applying to two visible things.

Check divorcing it from:
    if the noun is not married to the second noun, say "[The noun] is not married to [the second noun] anyway." instead.

Carry out divorcing it from:
    now the noun is not married to the second noun.

Report divorcing it from:
    say "[The noun] is now not married to [the second noun]."

When we unset the symmetrical relation on one side, it is automatically set or unset on the other. It is not necessary to say "the second noun is married to the noun" or "the second noun is not married to the noun", even though that is the case.

Section 7 - Setting and Unsetting Acquaintance (V-V Symmetrical)

Understand "introduce [someone] to [someone]" as introducing it to. Introducing it to is an action applying to two visible things.

Carry out introducing it to:
    now the noun knows the second noun.

Report introducing it to:
    say "You introduce [the noun] to [the second noun]. Now [the noun] is acquainted with [the list of people who are known by the noun], and [the second noun] is acquainted with [the list of people who are known by the second noun]."

Understand "announce [someone]" as announcing. Announcing is an action applying to one visible thing.

Carry out announcing:
    now every person knows the noun.

Report announcing:
    say "You announce [the noun] to the whole assembled company."

Understand "ostracise [someone]" as ostracising. Ostracising is an action applying to one visible thing.

Carry out ostracising:
    now every person does not know the noun.

Report ostracising:
    say "You cause everyone present to forget and pretend not to be acquainted at all with [the noun]."

And finally, setting groups:

Section 8 - Setting and Unsetting Familial Relations (Groups)

Understand "make [someone] adopt [someone]" as forcing it to adopt. Forcing it to adopt is an action applying to two visible things.

Carry out forcing it to adopt:
    now the noun is related to the second noun.

Report forcing it to adopt:
    say "Now [the second noun] is related to [the list of people related to the second noun]."

Understand "make [someone] disown [someone]" as forcing it to disown. Forcing it to disown is an action applying to two visible things.

Carry out forcing it to disown:
    now the second noun is not related to the noun.

Report forcing it to disown:
    say "Now [the second noun] is related to [the list of people who are related to the second noun], and [the noun] is related to [the list of people who are related to the noun]."

Notice that when we say "the second noun is not related", we remove that person from the group: they are now in a separate group of their own, while the rest of the group's members remain related to one another.

And finally, a long litany of test cases, complete with the relations lists:

Test acquaintance with "relations / introduce darcy to elizabeth / introduce darcy to wickham / announce mr bennett / relations / ostracise wickham / introduce georgiana to wickham / relations".

Test impression with "commend georgiana to elizabeth / relations / celebrate Mrs bennett / relations / traduce mrs bennett to darcy / relations / slander mrs bennett / relations".

Test notice with "draw the attention of darcy to elizabeth / relations / draw attention to mr bennett / relations / distract darcy from mr bennett / relations / outshine mr bennett / relations".

Test love with "embitter elizabeth toward darcy / relations / infatuate elizabeth with wickham / relations".

Test marriage with "marry elizabeth to darcy / relations / divorce elizabeth from darcy / relations".

Test alliance with "make mr bennett adopt georgiana / relations / make mrs bennett disown georgiana / relations".

Test fancying with "admire elizabeth / relations / loathe elizabeth / relations / flatter elizabeth / relations / unflatter elizabeth / relations / cause chaos / relations / relieve chaos / relations".

Test me with "test acquaintance / test impression / test notice / test love / test alliance / test fancying / test marriage".

433. Lugubrious Pete's Delicatessen

First, to set the scene:

paste.png "Lugubrious Pete's Delicatessen"

The Supermarket is west of the Delicatessen Counter. Lugubrious Pete is in the Delicatessen. "Lugubrious Pete, dolefully slicing meats and cheeses, serves at the counter." Alice, Beth, Gemma, Delia, and Eliza are women in the Supermarket.

The deli queue is a list of objects that varies.

Two processes compete here: one that fills the queue, the other which will empty it. The first process is the one which brings shoppers in to the counter, joining the back of the queue, which is where "add ... to ..." puts new entries by default:

Every turn when a woman is in the Supermarket and a random chance of 2 in 3 succeeds (this is the customer arriving rule):
    let the customer be a random woman in the Supermarket;
    now the customer is in the Delicatessen;
    if the player is in the Supermarket, say "[The customer] walks into the Delicatessen.";
    if the player is in the Delicatessen, say "[The customer] comes in from the Supermarket, and [if the number of entries in the deli queue is 0]can't believe her luck. The counter is free![otherwise]resignedly queues behind [the deli queue].";
    add the customer to the deli queue.

The competing process is the one which serves shoppers and thus gets rid of them again: unfortunately, it is slower. But Pete is fair if inefficient, and serves the customers in strict order of arrival. Each served customer is removed from the front of the list, and the others therefore all move up a place.

Every turn when the number of entries in the deli queue is not 0 and a random chance of 1 in 3 succeeds (this is the customer being served rule):
    let the customer be entry 1 of the deli queue;
    if the player is in the Delicatessen, say "Pete gives a droopy expression as he serves [customer], who nevertheless brightens and leaves.";
    if the player is in the Supermarket, say "[customer] emerges cheerfully from the Delicatessen Counter, and goes about her regular shopping.";
    now the customer is in the Supermarket;
    remove entry 1 from the deli queue.

Instead of waiting in the Delicatessen when the number of entries in the deli queue is not 0, say "Time passes, for [deli queue] quite as much as for yourself."

Test me with "wait / wait / wait / east / wait / wait / wait / wait / wait".

That completes the example, but here is a variation to show that queues need not empty from the front. The Deli already looks a pretty sexist establishment, with the customers all being women, but it is about to get a whole lot worse:

Modesty is a kind of value. The modesties are positively prim, buttoned up, modest, flirty, revealing and downright immodest. Every woman has a modesty. Alice is positively prim. Beth is downright immodest. Gemma is modest. Delia is flirty. Eliza is revealing.

We could then rewrite the service rule like so:

Every turn when the number of entries in the deli queue is not 0 and a random chance of 1 in 3 succeeds (this is the customer being served rule):
    let Pete's preference be the deli queue;
    sort Pete's preference in reverse modesty order;
    let the customer be entry 1 of Pete's preference;
    let the first in line be entry 1 of the deli queue;
    if the player is in the Delicatessen, say "[if the customer is the first in line]Pete gives a droopy expression as he serves [the customer], who nevertheless brightens and leaves.[otherwise]Outrageously, Pete scans the queue, notices [the customer] in her [modesty of the customer] clothes, and serves her next, while [the first in line] glares at him.";
    if the player is in the Supermarket, say "[The customer] emerges cheerfully from the Delicatessen Counter, and goes about her regular shopping.";
    now the customer is in the Supermarket;
    remove the customer from the deli queue.

It is now heartbreakingly difficult for Alice to obtain her sliced chorizo sausage.

176. Strictly Ballroom ★★

Many simple repetitions can effectively be done with a "now..." instruction: it is quicker to say

now every person is angry

than

repeat with offended party running through people:
    now the offended party is angry.

Repeat comes in handy when we have something a bit more complicated to do with each item:

paste.png "Strictly Ballroom"

A person can be alert or occupied. A person is usually alert.

When play begins:
    now the player is occupied.

Dance is a kind of value. The dances are waltzes, polkas, cha-chas, charlestons, fox-trots, tangos, lambadas, and two-steps.

The current round is a dance that varies.

Manner is a kind of value. The manners are swiftly, primly, energetically, suavely, seductively, elegantly, and badly.

Every turn: now the current round is a random dance.

Every turn:
    repeat with dancer running through people who are not the player:
        if dancer is alert:
            now dancer is occupied;
            let partner be a random alert person who is not the dancer;
            if partner is a person:
                now partner is occupied;
                say "[The dancer] [the current round][if a random chance of 1 in 5 succeeds] [a random manner][end if] with [partner]. ";
            otherwise:
                say "[paragraph break][The dancer] is forced to be a wallflower. Poor [dancer]. ";
    say paragraph break.

Notice we did not say "repeat with dancer running through alert people who are not the player...". This is because Inform would draw up a list of alert people at the beginning of the repeat, and not take into account which people became occupied partway through the repetition. If we want to make sure that each person dances only with one other person, we have to continue checking alertness each time we run through the repetition.

After all the partners are assigned, we can set up for the next turn by making everyone alert again, and for this we do not need "repeat":

Every turn: now every person is alert; now the player is occupied.

Before doing something to someone: now the noun is occupied.

Before doing something when the second noun is a person: now the second noun is occupied.

Instead of doing something to someone: say "You successfully distract [the noun]."

The Pacific Ballroom is a room. "A rather utilitarian space at the moment, since this is a class and not a party." Timmy, Tommy, Joey, George, Mary, Martha, Yvette, McQueen, Linus, and Patricia are people in the Pacific Ballroom.

Test me with "z / ask linus about blanket / z / z".

353. Emma ★★

To start with, let's understand "room" to mean "a group of people talking". These groups can grow and shrink as people come and go, so we'll want to name and rename them; and we're also going to need some rules to motivate people moving around, and a description to narrate how they behave when we're with them.

paste.png "Emma"

by the banquet table is a room. at the corner is a room. next to the doorway is a room. by the window is a room.

Social clump is a kind of value. The social clumps are vacancy, lone person, couple, cluster, group.

A room has a social clump. Understand the social clump property as describing a room.

Before printing the name of a room:
    say "a [social clump] ".

After looking:
    assign clumping;
    say "Elsewhere in the room, you can see [the list of rooms which are not the location]."

Understand "go to [any room]" as joining. Joining is an action applying to one visible thing. Carry out joining: move player to the noun. Report joining: do nothing.

Understand "examine [any room]" as looking toward. Looking toward is an action applying to one visible thing. Carry out looking toward a room: say "In that direction you see [a list of other people in the noun]."

When play begins: assign clumping. Every turn: assign clumping.

To assign clumping:
    repeat with space running through rooms:
        now the social clump of the space is vacancy;
        if the space contains exactly 1 person, now the social clump of the space is Lone person;
        if the space contains exactly 2 people, now the social clump of the space is Couple;
        if the space contains more than 2 people and the space contains fewer than 5 people, now the social clump of the space is cluster;
        if the space contains more than 4 people, now the social clump of the space is group.

The room description heading rule is not listed in the carry out looking rules.

A person has a number called longevity. The longevity of a person is usually 0. A person can be active or passive.

Definition: a person is other if it is not the player.

Every turn:
    repeat with mover running through other people:
        now the mover is active;
        increment the longevity of mover;
        if longevity of mover is greater than 3 or the mover is bored:
            assign value of spaces for the mover;
            let destination be the nicest room;
            if the destination is not the location of the mover:
                if the player can see the mover, say "[The mover] makes excuses and drifts off to join [the destination].[paragraph break]";
                move the mover to the destination;
                now the mover is complacent;
                now the longevity of the mover is 0;
                if the player can see the mover, say "[The mover] wanders over.[paragraph break]";
                assign clumping;
                now mover is passive.

A room has a number called attractiveness.

Definition: a room is nice if its attractiveness is 1 or more.

To assign value of spaces for (mover - a person):
    repeat with space running through rooms:
        now attractiveness of the space is 0;
        repeat with figure running through people in the space:
            if the mover is bored, decrease attractiveness of the space by 2;
            if the mover likes the figure, increment attractiveness of the space;
            if the mover dislikes the figure, decrement attractiveness of the space;
            if the mover desires the figure, increase attractiveness of the space by 2.

Liking relates various people to various people. The verb to like means the liking relation.

Disliking relates various people to various people. The verb to dislike means the disliking relation.

Attraction relates various people to various people. The verb to desire means the attraction relation.

Mr Weston, Mr Woodhouse, Mr Elton, Mr Knightley, and Frank Churchill are men. Mrs Weston, Mrs Bates, Miss Bates, Harriet Smith, Emma Woodhouse, and Jane Fairfax are women.

Harriet Smith likes Mr Elton. Harriet Smith desires Mr Elton. Harriet Smith likes Emma Woodhouse.

Mr Elton desires Emma Woodhouse.

Emma Woodhouse likes Harriet Smith and Mr Knightley. Emma Woodhouse dislikes Jane Fairfax.

Mr Knightley likes Emma Woodhouse, Mr Weston, and Mrs Weston. Mr Knightley desires Emma Woodhouse.

Jane Fairfax desires Frank Churchill. Jane Fairfax likes Frank Churchill.

Frank Churchill desires Jane Fairfax and Emma Woodhouse. Frank Churchill likes Jane Fairfax.

Miss Bates likes Jane Fairfax, Emma Woodhouse, and Mrs Bates.

Mr Weston likes Frank Churchill, Emma, Knightley, and Mrs Weston.

Mrs Weston likes Frank Churchill, Emma, Knightley, and Mr Weston.

Mrs Bates likes Miss Bates.

A person can be complacent or bored.

When play begins:
    repeat with character running through other people:
        let space be a random room;
        move character to space.

And now we use writing a paragraph about... to describe character behavior in groups, when we join them:

Rule for writing a paragraph about Frank Churchill:
    if the location contains a woman (called flirt) who is desired by Frank:
        say "[Frank Churchill] is talking with great animation and slightly more than becoming warmth to [the flirt][if an unmentioned other person is in the location], while [the list of unmentioned other people in the location] look on with varying degrees of amusement or irritation[end if].";
        repeat with character running through people in the location:
            if the character is not Churchill and the character is not the flirt, now the character is bored.

Rule for writing a paragraph about Mr Elton:
    if the location contains an unmentioned woman (called flirt) who is desired by Elton:
        say "[Mr Elton] hangs on the sleeve of [the flirt], offering an assortment of studied gallantries that make you wonder about his good sense.";
        repeat with character running through people in the location:
            if the character is not Elton and the character is not the flirt, now the character is bored.

Rule for writing a paragraph about Harriet Smith:
    if the location contains Emma and Emma is unmentioned:
        say "[Harriet] and [Emma] are conversing in low tones -- Harriet, apparently, being too shy to speak so that everyone can hear her."

Rule for writing a paragraph about Mr Knightley:
    if the location contains an unmentioned man (called the listener) who is not Mr Knightley:
        say "[Mr Knightley] is speaking with [the listener] about agricultural matters.";
        now the listener is complacent.

Rule for writing a paragraph about Miss Bates:
    say "[Miss Bates] is giggling about the weather[if an unmentioned other person is in the location]. This does not seem to compel the interest of [the list of unmentioned other people in the location][end if].";
    repeat with character running through people in the location:
        if the character is not Miss Bates and character is not Mrs Bates, now the character is bored.

Since this is just an example, we'll stop here, but there's no reason we couldn't write such paragraphs for everyone.

Test me with "z / z / z / look / x corner / x doorway / x window / x table / go to the table".

356. Happy Hour ★★

Often it is best to have an entire paragraph about the characters present in a room, but suppose we're narrating a large party with a lot of people moving around. In that case, it might be better to list everyone together, then add a few salient details by way of follow-up, like this:

paste.png "Happy Hour"

Before listing nondescript items:
    say "You can see [a list of people who are marked for listing] here. ";
    repeat with named party running through people:
        now the named party is not marked for listing;
    let count be the number of visible other people who are carrying something;
    if count is 0:
        say paragraph break;
        continue the action;
    let index be count;
    repeat with holder running through visible other people who are carrying something:
        if index is count, say "[The holder]";
        otherwise say "[the holder]";
        say " has [a list of things carried by the holder]";
        decrement index;
        make delimiter index of count.

The next part could be simpler, but for rigor we will write it in such a way that it will work whether or not the serial comma is in use. This requires some extra work.

To make delimiter (index - a number) of (count - a number), continuing or halting:
    if index is 0:
        if continuing, say ". [run paragraph on]";
        otherwise say ".";
    otherwise if index is 1:
        if count is 2, say " and ";
        otherwise say "[optional comma] and ";
    otherwise:
        say ", ".

To say optional comma:
    if the serial comma option is active:
        say ",".

And now the scene:

The Banquet Hall is a room. "A large cheery banner over the door (which, incidentally, vanishes when you approach it) reads: HELLO NEW INDUCTEES! WELCOME TO THE AFTERLIFE!"

Fred, George, and Larry are men in the Banquet Hall. Fred carries a dry martini. Larry carries a cream puff. Matilda and Louise are women in the Banquet Hall.

Definition: a person is other if it is not the player.

Every turn:
    let wanderer be a random other person;
    let place be the holder of the wanderer;
    let next place be a random room adjacent to the place;
    let the way be the best route from the place to the next place;
    try the wanderer going the way.

The Kitchen is west of the Banquet Hall. "Dominated by a pile of dirty plates which you imagine it will be someone's privilege to wash, later." Vanessa is a woman in the Kitchen. Vanessa carries a tray. On the tray is a salmon roll. The roll is edible.

Test me with "z / look / g / g / g ".