RB §2.1. Varying What Is Written

Before getting to actual recipes, many recipe books begin with intimidating lists of high-end kitchen equipment (carbon-steel pans, a high-temperature range, a Provencal shallot-grater, a set of six pomegranate juicers): fortunately, readers who have downloaded Inform already have the complete kitchen used by the authors. But the other traditional preliminaries, about universal skills such as chopping vegetables, boiling water and measuring quantities, do have an equivalent.

For us, the most basic technique of IF is to craft the text so that it smoothly and elegantly adapts to describe the situation, disguising the machine which is never far beneath the surface. This means using text substitutions so that any response likely to be seen more than once or twice will vary.

M. Melmoth's Duel demonstrates three basic techniques: an ever-changing random variation, a random variation changing only after the player has been absent for a while, and a message tweaked to add an extra comment in one special case. (Random choices can be quite specifically constrained, as Ahem shows in passing.) Fifty Ways to Leave Your Larva and Fifty Times Fifty Ways ★★★ show how a generic message can be given a tweak to make it a better fit for the person it currently talks about. Curare picks out an item carried by the player to work into a message, trying to make an apt rather than random choice. Straw Into Gold ★★★ demonstrates how to have Inform parrot back the player's choice of name for an object.

Another reason to vary messages is to avoid unnatural phrasing. Ballpark ★★★ turns needlessly precise numbers - another computerish trait - into more idiomatic English. (Likewise Numberless, though it is really an example demonstrating how to split behaviour into many cases.) Prolegomena shows how to use these vaguer quantifiers any time Inform describes a group of objects (as in "You can see 27 paper clips here.").

Blink, a short but demanding example from the extreme end of Writing with Inform, shows how the basic text variation mechanisms of Inform can themselves be extended. Blackout demonstrates text manipulation at a lower level, replacing every letter of a room name with "*" when the player is in darkness.

Inform's included extension Complex Listing allows us more control over the order and presentation of lists of items.

For how to change printed text to upper, lower, sentence, or title casing, see Rocket Man.

Examples

71. Fifty Ways to Leave Your Larva

We can use these substitutions to put together fairly complicated variations within a single piece of text:

paste.png "Fifty Ways to Leave Your Larva"

The Beekeeper's Palace is a room. Wasp is a woman in the palace. Drone is a man in the palace.

Instead of kissing someone:
    say "'[denial], [insult]! [boast]!'";

In this context, [denial] is understood to refer to the denial property of the noun -- but we could spell it out with "denial of the noun" if we wanted to.

A person has some text called denial. The denial of a person is usually "Stand back". The denial of Drone is "You forget yourself"

A person has some text called insult. The insult of a person is usually "Grasshopper". The insult of Wasp is "Larva".

A person has some text called boast. The boast of a person is usually "I am ferocious". The boast of Drone is "I have ferocious allies".

And then it would be trivial to insert further rules using these responses:

Instead of attacking someone:
    say "'Get away, [insult]!'"

Test me with "kiss wasp / hit wasp / hit drone / kiss drone".

169. Ahem

As we see in the example here, it is possible to use slashed variations in more than one place in a phrase, and to offer a number of separate forms. The main rule of thumb to remember is that value inputs for the phrase should always be separated by some text; so

To do/follow (chosen rule - a rule) exactly/precisely/just/-- (N - a number) time/times:
    ....

would cause a problem when we tried to call it with

follow the throat-clearing rule 2 times.

In general, we probably don't need to make our phrase definitions quite so flexible as this, but it's a good idea to account for "a" vs. "the", and for the possibility of using singular and plural forms, especially when writing extensions or other source to be shared.

paste.png "Ahem"

To do/follow (chosen rule - a rule) exactly/precisely/just (N - a number) time/times:
    repeat with index running from 1 to N:
        follow chosen rule.

This is the throat-clearing rule:
    say "'Ahem,' says [a random visible person who is not the player]."

After waiting:
    do the throat-clearing rule just one time.

Instead of listening:
    follow the throat-clearing rule precisely three times.

Instead of smelling:
    follow the throat-clearing rule exactly 2 times.

Chateau Marmont is a room. Tom, Jack, Zsa-Zsa, and Wilma-Faye are people in the Chateau. Zsa-Zsa and Wilma-Faye are women.

Test me with "wait / smell / listen".

174. Numberless

paste.png "Numberless"

The Rambling Warren is a room.

When play begins:
    let N be a random number between 1 and 5;
    if N is 1:
        say "N is one.";
    otherwise if N is 2:
        say "N is two.";
    otherwise if N is 3:
        say "N is three.";
    otherwise:
        say "N is more than the number of your toes."

The final "otherwise" here will fire only if none of the earlier conditions applies; we could leave it out and print nothing in the case that N is 4 or 5.

The more compact way to do this is to create a list of values that our number could match; in many programming languages this is called a switch statement. For example:

When play begins:
    let Y be a random number between 6 and 10;
    if Y is:
        -- 6: say "Six is the magic number!";
        -- 7: say "The number of the day is seven!";
        -- otherwise: say "Today's magic number is boring."

As a final option, we can use a construction we've seen only briefly before now: a table. The use of tables will be explained more fully in their own chapter, but here we see in brief that we can assign a number of values to one column of a table and then use that table to look up output:

When play begins:
    let X be a random number between 11 and 14;
    if X is a number listed in the Table of Switching, say "[output entry][paragraph break]";
    otherwise say "X is greater than the number of your noses!"

Table of Switching

number

output

11

"X is eleven!"

12

"X is twelve!"

13

"X is thirteen!"

Test me with "z".

As we shall see, things other than text can be stored in tables, so we could also use a table as a way to look up objects or even rules to carry out.

178. M. Melmoth's Duel

paste.png "M. Melmoth's Duel"

Saint-Germain-des-Prés is a room. "Haunt of artists, of the coffee-drinking sort, and of cafés, of the artist-haunted sort, you once again find yourself outside M. Melmoth's hotel. Today [one of]the recently-fallen rain runs down the gutters of the 6th[or]sunlight glints even off the blackened windows of the Abbey[or]crowds of vulgar children play chase around the lampposts[at random], and you long to be indoors."

The Hôtel d'Alsace is inside from Saint-Germain-des-Prés. "Typical. Oscar writes you a letter announcing his own imminent demise - 'My wallpaper and I are fighting a duel to the death. One or other of us has got to go.' - and then you get there and he's out, no doubt procuring paint the colour of absinthe, if he isn't procuring the painter."

Tint is a kind of value. The tints are green, aquamarine and darkish purple.

The wallpaper is fixed in place in the Hôtel. The wallpaper has a tint. "In this light, the wallpaper has a distinctly [tint of the wallpaper] wash. [if the tint of the wallpaper is darkish purple]You particularly dislike purple.[end if]"

Before going to the Hôtel: now the wallpaper is a random tint.

After going from the Hôtel, say "You leave, shaking your head. But within twenty-four hours, you are back, as you always knew you would be."

Test me with "in / out / look / in / out / look".

249. Olfactory Settings

While this isn't very interesting as IF, it runs through most of the adaptive-text tricks.

paste.png "Olfactory Settings"

The Doghouse is a room. "Not so much a place as a state of being."

The player carries a ticket to the opera, some papers, and a bouquet of flowers. The bouquet is ambiguously plural.

Instead of eating something inedible, say "[The noun] [don't] seem likely to agree with [us] at all. [We][']d be wiser to leave [regarding the noun][them] alone."

Instead of touching something: say "[regarding the noun][Those] [are] all prickly."

Instead of smelling something: say "[Our] nose [regarding nothing][are] too weak to get much smell from [regarding the noun][those]."

Instead of smelling the bouquet: say "[regarding the noun][They]['re] lovely."

Instead of tasting something:
    say "Whew, [regarding the noun][are] [those] ever nasty!"

Test me with "x ticket / eat it / eat them / touch it / touch them / smell it / smell them / taste it / taste them / x papers / eat it / eat them / touch them / smell them / taste them / x bouquet / eat it / eat them / touch them / smell them / taste them".

252. Responsive

The most straightforward way to alter the response text for something in the standard rules is to select the Index tab, then select Actions, then pick the particular action whose text we'd like to alter. Under action details, there will be icons that look like speech bubbles.

Clicking on the speech bubble will show what the current response text is, and give us an option called "set".

If we click "set", this will automatically paste in the response name that we need to change. We can put this inside a "when play begins" rule in order to make that change take effect from the start of the game, like so:

paste.png "Responsive"

An Anonymous B613 Cell is a room. "There isn't much to see in this bare room. What there is, you've already seen sometime in the last twenty years."

When play begins:
    now print empty inventory rule response (A) is "[We] [have] absolutely nothing.".

Test me with "i".

343. Prolegomena

Room descriptions often make the player character out to be a bit of a savant, able to count whole stacks of items at a glance: "You see 27 paper clips here."

We can adjust this behavior to our liking, though, with the printing a number... activity, as follows:

paste.png "Prolegomena"

The Editor's Office is a room. The desk is a supporter in the Editor's Office.

A red pencil is a kind of thing. 12 red pencils are on the desk.

A letter is a kind of thing. 12 letters are on the desk. Understand "correspondence" as a letter.

Rule for printing the plural name of a letter:
    if the listing group size is greater than 7, say "correspondence";
    otherwise say "letters".

Rule for printing a number of something (called the target) when the listing group size is greater than 7:
    say "[one of]some [or]various [or]an assortment of [at random]";
    carry out the printing the plural name activity with the target.

This general rule can of course be overridden by more specific ones; for instance, if we want to take the opportunity to comment on the viewpoint character's appetite for instruments of correction:

Rule for printing a number of red pencils (called the target) when the listing group size is greater than 10:
    carry out the printing the plural name activity with the target;
    say " in nearly-sufficient quantity".

Test me with "get two letters / look / get a pencil / i / get pencil / g / g / look / i / get all / i".

345. Wesponses

If we want to change individual responses to player action, then the best thing to do is to use the response facility to modify those selections, as shown in the chapter on Responses.

However, suppose what we want is to give the parser a speech impediment that slightly alters all of the responses it issues. For this purpose, we might need to do a bit of text replacement...

paste.png "Wesponses"

The Office is a room. Barry Kripke is a man in the Office.

The response inhibition is initially false.

Rule for issuing the response text of a response (called R) when response inhibition is false:
    now response inhibition is true;
    let output be "[text of R]";
    now response inhibition is false;
    replace the text "r" in output with "w";
    replace the text "R" in output with "W";
    say "[output]".

Test me with "i / x barry / listen / waffle / jump"

Notice that this doesn't affect the printed names of objects in the room description or other kinds of output text -- only those that are issued by the response mechanism.

It would also not work to try to give our parser a nervous personality by simply adding "Um, " to the beginning of each response, because responses are not guaranteed to be full standalone sentences. For example, we could imagine writing

Rule for issuing the response text of a response (called R) when response inhibition is false:
    now response inhibition is true;
    let output be "Um, [text of R]";
    now response inhibition is false;
    say "[output]".

but here is what the room description would say as a result:

Office
Um, You Um, can see Barry KripkeUm, here

413. Rocket Man

We can now change the case of any text produced by a "to say..." phrase. This is often useful when we would like to make use of a standard say phrase in some new context. Say, for instance, that we would like to "[is-are the list...]" in a context that needs the first letter to be capitalized.

We could write a new say phrase, such as "to say is-are the list of (N - a description of objects) in sentence capitalization"; but there is an easier way, and that is to set a text variable to the output of the to say phrase, and then print that text in the case of our choice.

For example:

paste.png "Rocket Man"

Instead of going somewhere from the spaceport when the player carries something:
    let N be "[is-are the list of things carried by the player] really suitable gear to take to the moon?" in sentence case;
    say "[N][paragraph break]".

The Spaceport is a room. North of the Spaceport is the Rocket Launch Pad. The player carries a stuffed bear, a chocolate cookie, and a book.

The description of the book is "It is entitled [italic type]Why Not To Take [sentence cased inventory] To The Moon[roman type]."

To say sentence cased inventory:
    let N be "[a list of things carried by the player]" in title case;
    say "[N]".

Test me with "n / x book".

421. Blackout

In this example, we want the names of rooms to be asterisked out if the player wanders around without the benefit of a candle. We can do this by treating the room names as text, then replacing every letter:

paste.png "Blackout"

Tiny Room is a dark room. Absurdly Long-Named Room is a dark room. It is west of Tiny Room.

The Candle Factory is north of Tiny Room. It contains a beeswax candle. The beeswax candle is lit.

Rule for printing the name of a dark room:
    let N be "[location]";
    replace the regular expression "\w" in N with "*";
    say "[N]".

Test me with "w / look / e / n / get candle / s / w".

Notice that the hyphen in the Absurdly Long-Named Room does not get replaced. We could replace even that, if we liked, with

    replace the regular expression "\S" in N with "*";

which would catch every character that is not a space.

439. Curare

paste.png "Curare"

A thing has a number called the last use. The last use of a thing is usually 0.

Definition: a thing is old if its last use is 12 or less.

The actual number chosen in this definition is pretty much irrelevant: the main thing is that we want to establish relative values. The lower the "last use" number of an item, the older that item should be understood to be, as we see here:

To decide which thing is cyclically random (collection - a description of objects):
    let choice be the oldest member of the collection;
    now the last use of the choice is the turn count;
    decide on choice.

This phrase will select, from the collection of objects passed to it, the one that has been mentioned least recently. This means that if we consult it repeatedly about the same collection, it will begin to cycle predictably; but if new items are added to the collection, it will mention these first before returning to the previous cycle. Now we can use this:

After taking inventory:
    say "You stare morosely at [the cyclically random thing carried by the player], wondering what you're ever going to find to do with it."

We could have said "You stare morosely at [the oldest thing carried by the player]" here, but doing so would not have set the "last use" property correctly, so we would not get the cycling behavior that we're looking for.

The Evidence Room is a room. Some shelves are scenery supporters in the Evidence Room. A box is a kind of container which is open and not openable. On the shelves is a box. It contains a deformed bullet and a driver's license.

The player carries a steel fish hook, a Chinese passport, a tube of synthetic curare, and an envelope full of Euros.

Test me with "i / i / i / i / i / i / get all from box / i / i / i".

454. Blink

Suppose we are writing a game in which the mood of the piece changes, and we would like to have lots of descriptions that vary according to its current state. We might in that case want to create our own "by atmosphere" token, to control text variations, like this:

paste.png "Blink"

Atmosphere is a kind of value. The atmospheres are normal, melancholy, and creepy.

The current atmosphere is an atmosphere that varies.

To say by atmosphere -- ending say_one_of with marker I7_SOO_ATM:
    (- {-close-brace} -).

Since we're operating within the untyped Inform 6, we can make use of the fact that kinds of value are (internally) just constants, enumerated in the same order in which they were originally defined. In other words, "normal" at the I6 level translates to 1, "melancholy" to 2, and "creepy" to 3; so we can return the value of the current atmosphere, and thereby select option 1, 2, or 3:

Include (-
[ I7_SOO_ATM oldval count;
    if (count < (+ current atmosphere +)) return count;
    return (+ current atmosphere +); ];
-)

And that concludes the hard part. Now to test that it works:

The Flat is a room. "A small [one of]but cozy[or]depressing[or]imprisoning[by atmosphere] flat. Outside the window, the sun is [one of][or][or]apparently [by atmosphere]shining and there is a brisk breeze through the leaves of the birch trees. [one of]It would be quite nice weather for a walk[or]The rest of the world apparently has no appreciation of what you suffer[or]It all looks deceptively normal[by atmosphere]."

Instead of waiting when the current atmosphere is normal:
    say "Everything stretches wide and flat for just a moment, as though all the world around you were painted on a thin rubber sheet that is being [italic type]stretched[roman type]. Then it snaps back into place, leaving your ears ringing. But that little glitch was enough to warn you. Someone is tampering with space-time again. Someone very close by.";
    now the current atmosphere is creepy.

Test me with "look / z / look".

245. Fun with Participles ★★

Mostly the Standard Rules use verbs adapted to finite forms ("he jumped", "we take the hammer", and so on). But Inform can also produce participles to describe actions that are ongoing: "he is carrying the fedora" or "taking the hammer..."

In this example, we give non-player characters actions to perform and then have Inform dynamically describe what they're doing when the player chooses to look.

We start by establishing the idea that a verb can describe a particular action:

paste.png "Fun with Participles"

Section 1 - Descriptive Functionality

Describing relates various verbs to various action names. The verb to describe means the describing relation.

To look around is a verb. The verb look around describes the looking action.

To stand about is a verb. The verb stand about describes the waiting action. To look bored is a verb. The verb look bored describes the waiting action. To waste time is a verb. The verb waste time describes the waiting action.

To jump is a verb. To leap is a verb. To pirouette is a verb. The verb jump describes the jumping action. The verb leap describes the jumping action. The verb pirouette describes the jumping action.

Now we need to give every character some sort of idle activity. By default, we'll have people just be waiting, but allow for that idle activity to change into something more interesting if the player has told them to do something else.

A person has an action name called the current idle. The current idle of a person is usually the waiting action.

Rule for writing a paragraph about someone (called chosen person) when a verb describes the current idle of the chosen person:
    say "[The chosen person] [are] here, [present participle of a random verb that describes (the current idle of the chosen person)]."

Instead of someone doing something:
    now the current idle of the person asked is (the action name part of the current action);
    continue the action.

A persuasion rule:
    persuasion succeeds.

Section 2 - Scenario

Lab is a room. The fedora is a wearable thing in the Lab. Clark is a man in the Lab.

And just to give past participles a test-drive as well, let's make Clark a bit of a drama king:

After Clark doing something when a verb describes (the action name part of the current action):
    say "'Fine, have it your way!' Clark exclaims. 'But I have [past participle of a random verb that describes (the action name part of the current action)] for the last time!'";
    rule succeeds.

Test me with "look / Clark, jump / look / Clark, look / look / Clark, wait".

246. Variety ★★

Verbs can be related to other things by relations. We've seen that it's possible for a verb to "mean" a relationship. But we can also create a relation between verbs and actions. For instance, we can tell Inform that "take", "get", and "acquire" are all valid ways to describe the action of taking, and then allow it to pick a verb randomly to describe whatever action just occurred.

paste.png "Variety"

Section 1 - Descriptive Functionality

Describing relates various verbs to various action names. The verb to describe means the describing relation.

To take is a verb. To acquire is a verb. To get is a verb.

The verb take describes the taking action. The verb acquire describes the taking action. The verb get describes the taking action.

To drop is a verb. To put down is a verb. To discard is a verb. The verb drop describes the dropping action. The verb put down describes the dropping action. The verb discard describes the dropping action.

To sniff is a verb. To smell is a verb. The verb sniff describes the smelling action. The verb smell describes the smelling action.

To jump is a verb. To leap is a verb. To pirouette is a verb. The verb jump describes the jumping action. The verb leap describes the jumping action. The verb pirouette describes the jumping action.

After an actor doing something when the noun is nothing and a verb describes (the action name part of the current action) (this is the apply random verbs to describing nounless actions rule):
    say "[The actor] [verb rendering applied to a random verb that describes (the action name part of the current action)].";
    rule succeeds.

After an actor doing something to something when a verb describes (the action name part of the current action) (this is the apply random verbs to describing actions rule):
    say "[The actor] [verb rendering applied to a random verb that describes (the action name part of the current action)] [the noun].";
    rule succeeds.

To decide which text is the rendering of (V - verb) (this is verb rendering):
    decide on "[adapt V]".

Section 2 - Scenario

Lab is a room. The table is here. The bat and the ball are on the table.

Test me with "get ball / drop ball / get bat / drop bat / smell ball".

247. Variety 2 ★★

Some of our default actions establish relations between items in the world, and reporting on the relation ("You are now carrying the fedora") can be a valid response alongside reporting on the action itself ("You take the fedora").

To do this, we need to teach Inform explicitly which relations are the results of actions, then check this when reporting on actions:

paste.png "Variety 2"

Section 1 - Descriptive Functionality

Describing relates various verbs to various action names. The verb to describe means the describing relation.

Table of Action Results

related action

relation

the taking action

the carrying relation

the wearing action

the wearing relation

the taking off action

the carrying relation

To take is a verb. To acquire is a verb. To get is a verb.

The verb take describes the taking action. The verb acquire describes the taking action. The verb get describes the taking action.

To drop is a verb. To put down is a verb. To discard is a verb. The verb drop describes the dropping action. The verb put down describes the dropping action. The verb discard describes the dropping action.

To sniff is a verb. To smell is a verb. The verb sniff describes the smelling action. The verb smell describes the smelling action.

To jump is a verb. To leap is a verb. To pirouette is a verb. The verb jump describes the jumping action. The verb leap describes the jumping action. The verb pirouette describes the jumping action.

To don is a verb. The verb don describes the wearing action.

To doff is a verb. The verb doff describes the taking off action.

After an actor doing something when the noun is nothing and a verb describes (the action name part of the current action) (this is the apply random verbs to describing nounless actions rule):
    say "[The actor] [verb rendering applied to a random verb that describes (the action name part of the current action)].";
    rule succeeds.

After an actor doing something to something when a verb describes (the action name part of the current action) (this is the apply random verbs to describing actions rule):
    let current action name be the action name part of the current action;
    if a random chance of 1 in 2 succeeds and the current action name is a related action listed in the Table of Action Results:
        choose a row with the related action of current action name in the Table of Action Results;
        let R be the relation entry;
        let subject be the actor;
        let chosen object be the noun;
        say "[The subject] [are] now [present participle of a random verb that means R] [the chosen object].";
    else:
        say "[The actor] [verb rendering applied to a random verb that describes (the action name part of the current action)] [the noun].";
    rule succeeds.

To decide which text is the rendering of (V - verb) (this is verb rendering):
    decide on "[adapt V]".

To say infinitive of (V - a verb): (- {V}(1); -).

To say past participle of (V - a verb): (- {V}(2); -).

To say present participle of (V - a verb): (- {V}(3); -).

Section 2 - Scenario

Lab is a room. The fedora is a wearable thing in the Lab.

Test me with "wear the fedora / take off the fedora / wear fedora / take off fedora".

250. Relevant Relations ★★

Suppose that we wanted authors to be able to indicate which relations should or should not be included in room descriptions, and have the system dynamically honor that instruction.

Inform already knows about verbs for describing supporting, containment, carrying, and wearing, so we could write a set of instructions to handle such cases. To do this, we're using the "writing a paragraph about" activity, which is described in the chapter on activities.

paste.png "Relevant Relations"

Section 1 - Procedure

Rule for writing a paragraph about something (called item):
    now the current paragraph is { };
    say "[one of][regarding item]There [are] [an item] here[or][We] [can see] [an item] here[at random]. [run paragraph on]";
    follow the descriptive rules for the item;
    repeat with new item running through the current paragraph:
        now the prior named object is nothing;
        if new item is not the item:
            follow the descriptive rules for the new item;
    say paragraph break.

Rule for writing a paragraph about someone (called chosen person):
    now the current paragraph is { };
    say "[one of][regarding chosen person][The chosen person] [are] here[or][We] [can see] [a chosen person] here[at random]. [run paragraph on]";
    follow the descriptive rules for the chosen person;
    repeat with new item running through the current paragraph:
        now the prior named object is nothing;
        if new item is not the chosen person:
            follow the descriptive rules for the new item;
    say paragraph break.

The descriptive rules are an object-based rulebook.

Definition: a container is see-through:
    if it is transparent:
        yes;
    if it is open:
        yes;
    no.

A descriptive rule for a see-through container (called item) (this is the describe contents rule):
    describe the containment relation for item.

A descriptive rule for a supporter (called item):
    describe the support relation for item.

A descriptive rule for a person (called item):
    describe the wearing relation for the item.

A descriptive rule for a person (called item):
    describe the carrying relation for the item.

The current paragraph is a list of things that varies.

Before printing the name of something (called mentioned target) while writing a paragraph about something:
    add the mentioned target to the current paragraph, if absent.

To describe (R - a relation of objects) for (item - a thing):
    if a thing to which item relates by R is a thing:
        say "[The item with pronoun] [verb rendering applied to a random verb that means R] [the list of things to which item relates by R with indefinite articles]. [run paragraph on]"

To decide which text is the rendering of (V - verb) (this is verb rendering):
    decide on "[adapt V]".

To say (T - a thing) with pronoun:
    if T is the prior named object:
        say "[regarding T][They]";
    else:
        say "[The T]"

Section 2 - Scenario

The Space Elevator is a room. "Mercifully, there aren't any windows. The ability to see how far up you are would almost certainly make you ill."

The luggage rack is a supporter in the Space Elevator. The suitcase is a closed openable container on the luggage rack. The bouquet is on the luggage rack.

Clark is a man in the Space Elevator. Clark is carrying a box of cupcakes. Clark is wearing a t-shirt. The description of the box of cupcakes is "They're the latest confection from Red Velvet Planet, the Martian bakery."

Persuasion rule: persuasion succeeds.

We can if we like then add alternate names for these relations that will be randomly swapped in some of the time. For instance:

To sport is a verb. The verb to sport means the wearing relation.

To hold up is a verb. The verb to hold up means the support relation.

Test me with "clark, drop the box / look / clark, take the suitcase / look / clark, get bouquet".

One might, hypothetically, imagine going even further than this and simply designating relations as either "important" or "unimportant" -- perhaps changing the relation's designation at runtime. Relations are not themselves allowed to have properties, however.

251. History Lab ★★

The examples Variety and Narrative Register show how verbs can be associated with particular actions. Here, we use the same principle so that we can report to the player what was last done to a particular object, either by the player or by someone else.

To do this, we need to use the idea of stored actions from the Advanced Actions chapter.

paste.png "History Lab"

Section 1 - Procedure

An object has an action called the last action.

Describing relates various verbs to various action names. The verb to describe means the describing relation.

To take is a verb. The verb take describes the taking action.
To drop is a verb. The verb drop describes the dropping action.
To look at is a verb. The verb look at describes the examining action.
To examine is a verb. The verb examine describes the examining action.

After an actor doing something to something:
    if a verb describes the action name part of the current action:
        now the indefinite article of the noun is "the";
        now the last action of the noun is the current action;
    continue the action.

After printing the name of something (called item):
    if the last action of the item is not waiting and the last action of the item is not the current action:
        let chosen action-name be the action name part of the last action of the item;
        let chosen actor be the actor part of the the last action of the item;
        if a verb describes the chosen action-name:
            let the chosen verb be a random verb that describes the chosen action-name;
            say " [if the chosen actor is the player][we][else][chosen actor][end if] [adapt chosen verb in past tense]";

Section 2 - Scenario

Lab is a room. It contains a box. The box contains a newspaper. Clark is a man in the Lab.

A persuasion rule:
    persuasion succeeds.

Test me with "x box / look / x newspaper / look / clark, x newspaper / clark, get box / clark, drop box / look / take box / i / smell box / i".

Notice that smelling the box does not change the box's description because we haven't gotten around to defining a smell or sniff verb.

60. Ballpark ★★★

Sometimes it is more sensible to describe numbers roughly than in exact terms. For instance, we might want to have our player perceive "many people" rather than "forty-two people" on entering a room. To achieve this, we might write our own "to say" phrase.

paste.png "Ballpark"

To say (count - a number) in round numbers:
    repeat through the Table of Numerical Approximation:
        if count is less than threshold entry:
            say "[approximation entry]";
            rule succeeds.

Phrases will be explained more thoroughly in a later chapter, but as we have already seen in the examples, we can make a "To say..." phrase that will allow us to create our own text substitutions. In this case, we are going to replace the specific number with a vaguer one chosen from a chart, so:

Table of Numerical Approximation

threshold

approximation

1

"no"

2

"one"

3

"a couple of"

6

"a few"

11

"some"

21

"many"

1000

"lots and lots of"

The idea here is that we will work our way through the table until we hit a line where the threshold number is higher than the number we want to express, and then print that output: so if we have less than one item, we'll print "no"; if we have more than none but less than two, we'll print "one"; if we have less than three, we'll print "a couple of"; if we have three, four, or five (but not six), we'll print "a few."

A room has a number called the population. The population of a room is usually 0. The description of a room is usually "You observe [population of the location in round numbers] [if population of the location is 1]person [otherwise]people [end if]here.".

The Stadium is a room. The Hot Dog Stand is west of the Stadium. The Women's Restroom is south of the Stadium.

The population of the Stadium is 500. The population of the Hot Dog Stand is 3. The population of the Restroom is 750.

Test me with "w / e / s".

72. Fifty Times Fifty Ways ★★★

There is only so much we can cram into a text property, so being able to swap in properties is useful but limited. Fortunately, we can also, if we want, create new phrases for how to say things in brackets:

paste.png "Fifty Times Fifty Ways"

The Beekeeper's Palace is a room. Wasp is a woman in the palace. Drone is a man in the palace.

A person can be fierce or mellow. Wasp is fierce. Drone is mellow. A person can be calm or angry. A person is usually calm. A person has some text called insult. The insult of a person is usually "Grasshopper". The insult of Wasp is "Larva".

Instead of kissing someone:
    say "'[denial for the noun], [insult for the noun]! [boast]!'";

Now to provide some meaning to these bracketed forms. We'll start with the easy one:

To say boast:
    say "I have ferocious allies".

This is a "to say" phrase; we will learn more about phrases in a later chapter, but for now it may be enough to observe that whatever we write after "to say..." becomes a valid substitution in bracketed speech. In this particular case there is no advantage to using the boast token rather than spelling the text out in the quotation, but we might in theory add further instructions to randomize the output, for instance.

To say phrases can be more complex, as well, since we can have them incorporate extra information:

To say insult for (speaker - a person):
    if speaker is angry, say "[the insult of the noun]";
    otherwise say "small one".

Here where we have (speaker - a person), we are leaving a slot which we can later fill in, madlibs-like, with any person we like. That is why we can write "insult for the noun": we are summoning the To say phrase and telling it to fill in the identity of the unknown speaker with the noun.

This differs from "insult of the noun" in the previous example; in that case, each person had his own insult property, and were merely printing that property out. Here we are actually telling Inform to calculate anew what the insult should be, and giving it some instructions about how to do that.

Our instructions can also get arbitrarily complex:

To say denial for (speaker - a person):
    if speaker is calm:
        say "You must not";
    otherwise if speaker is female:
        say "Stand back";
    otherwise:
        say "You forget yourself".

Instead of attacking someone:
    now the noun is angry;
    say "'Get away, [insult]!'"

Test me with "kiss wasp / hit wasp / kiss wasp / kiss drone / hit drone / kiss drone".

So the effects we can get with text substitutions are quite flexible. We could even, if we wanted, fill in the substitutions by random choice, or by selecting items from a long list or table, should we have so bellicose a set of characters that they cannot make do with one or two insulting remarks apiece.

248. Narrative Register ★★★

As we saw in "Variety", we can associate verbs with particular actions and call them up as needed. If we do that, though, we can also store additional information about those verbs and use that information to select the ideal verb to use in a particular situation.

In this example, we create a table of verbs and their meanings, together with some connotative information. Each time we report an action, we then score all the available verbs to decide which is the most suitable to use at the moment. This allows us to change the narrator's diction change mid-game and have the action descriptions change as well.

Moreover, because we're using adaptive verbs, these responses will automatically inflect properly even if we change the story tense and viewpoint.

paste.png "Narrative Register"

Section 1 - Descriptive Functionality

Describing relates various verbs to various action names. The verb to describe means the describing relation.

To take is a verb. To acquire is a verb. To get is a verb. To gain is a verb. To obtain is a verb. To pick up is a verb. To bag is a verb. To procure is a verb. To score is a verb. To grab is a verb. To snag is a verb. To snatch is a verb. To collect is a verb.

To drop is a verb. To put down is a verb. To discard is a verb. To throw away is a verb. To dispose of is a verb. To set down is a verb. To toss aside is a verb. To ditch is a verb. To abandon is a verb. To dump is a verb. To jettison is a verb. To abjure is a verb. To foresake is a verb. To dispense with is a verb.

After an actor doing something to something when a verb describes (the action name part of the current action) (this is the apply random verbs to describing actions rule):
    score the relevant verbs;
    sort the Table of Verb Meanings in reverse relevance order;
    choose row 1 in the Table of Verb Meanings;
    let top score be the relevance entry;
    sort Table of Verb Meanings in random order;
    repeat through the Table of Verb Meanings:
        if relevance entry is top score:
            say "[The actor] [verb rendering applied to (word entry)] [the noun].";
            erase relevance;
            rule succeeds.

To decide which text is the rendering of (V - verb) (this is verb rendering):
    decide on "[adapt V]".

To score the relevant verbs:
    repeat through the Table of Verb Meanings:
        if the meaning entry is (the action name part of the current action):
            increase relevance entry by 1;
            repeat with chosen connotation running through connotations entry:
                if the chosen connotation is listed in the current register:
                    increase relevance entry by 1;
                otherwise:
                    decrease relevance entry by 1.

To erase relevance:
    repeat through Table of Verb Meanings:
        now relevance entry is 0.

A tonality is a kind of value. The tonalities are pompous, archaic, slangy, upbeat, downbeat.

Connoting relates various verbs to various tonalities. The verb to connote means the connoting relation.

The current register is a list of tonalities that varies. The current register is { }.

When play begins:
    repeat through the Table of Verb Meanings:
        now the word entry describes the meaning entry;
        now relevance entry is 0;
        repeat with chosen tone running through the connotations entry:
            now the word entry connotes the chosen tone.

Table of Verb Meanings

word

meaning

connotations

relevance ( a number )

the verb take

the taking action

{ }

the verb acquire

the taking action

{ pompous }

the verb get

the taking action

{ }

the verb gain

the taking action

{ }

the verb obtain

the taking action

{ pompous }

the verb pick up

the taking action

{ }

the verb bag

the taking action

{ slangy }

the verb score

the taking action

{ slangy, upbeat }

the verb procure

the taking action

{ archaic }

the verb grab

the taking action

{ slangy }

the verb snag

the taking action

{ slangy }

the verb snatch

the taking action

{ slangy }

the verb collect

the taking action

{ }

the verb discard

the dropping action

{ pompous }

the verb drop

the dropping action

{ }

the verb put down

the dropping action

{ }

the verb toss aside

the dropping action

{ }

the verb ditch

the dropping action

{ slangy }

the verb throw away

the dropping action

{ }

the verb dispose of

the dropping action

{ }

the verb set down

the dropping action

{ }

the verb abandon

the dropping action

{ downbeat }

the verb dump

the dropping action

{ downbeat }

the verb abjure

the dropping action

{ archaic }

the verb foresake

the dropping action

{ archaic }

the verb jettison

the dropping action

{ pompous }

the verb dispense with

the dropping action

{ pompous }

Section 2 - Changing Tone Mid-Game

Understand "new tone" as changing the tone. Changing the tone is an action out of world.

Carry out changing the tone:
    now the current register is { };
    if a random chance of 1 in 4 succeeds:
        say "Your narrator will now adopt an ordinary tone.";
        rule succeeds;
    let rando be a random tonality;
    add rando to the current register, if absent;
    say "Your narrator will now be [rando]."

Section 3 - Scenario

Lab is a room. The table is here. The bat and the ball are on the table.

Test me with "get ball / drop ball / get bat / drop bat / new tone / get all / drop all / new tone / get all / drop all".

305. Straw Into Gold ★★★

paste.png "Straw Into Gold"

The Cell is a room. Rumpelstiltskin is an improper-named man in the Cell. Rumpelstiltskin can be identified or unidentified. Rumpelstiltskin is unidentified.

R-name is a kind of value. The R-names are dwarf, guy, dude, and man-thing. Rumpelstiltskin has an R-name. Understand "[R-name]" as Rumpelstiltskin.

Our example is slightly complicated by the fact that "man" is a name already known to Inform, so we can't re-use it as a kind of value. This is possible to work around, though:

Understand "man" as man-thing.

Now we borrow from the Activities chapter to look at the exact wording of the player's command:

After reading a command:
    if the player's command includes "[R-name]",
        now the R-name of Rumpelstiltskin is the R-name understood;
    if the player's command includes "Rumpelstiltskin":
        now Rumpelstiltskin is identified;
        now Rumpelstiltskin is proper-named.

Rule for printing the name of Rumpelstiltskin when Rumpelstiltskin is unidentified:
    if the R-name of Rumpelstiltskin is man-thing:
        say "man";
    otherwise:
        say "[R-name]".

Test me with "x dwarf / x guy / x dude / look / x rumpelstiltskin / look / x man".

RB §2.2. Varying What Is Read

Making the printed text adapt to circumstances only makes half of the conversation graceful: the other half is to allow the player's commands to have a similar freedom. The things the player can refer to should always respond to the names which would seem natural to the player. Inform provides a variety of techniques for understanding words always, or only under certain conditions; and, if need be, we can also get direct access to what the player has typed in order to examine it with regular expressions. (This last resort is rarely necessary.)

First Name Basis shows how to assign names to things or to kinds of thing - if, for instance, we want the player to be able to refer to any man as "man" or "gentleman":

Understand "man" or "gentleman" as a man.

We may also sometimes want to give names that are specifically plural, as in

A duck is a kind of animal. Understand "birds" as the plural of duck.

or

Understand "birds" as the plural of the magpie.

Vouvray ★★ demonstrates.

A common challenge arises when two objects have names that overlap or are related, and we wish Inform to choose sensibly between them: for instance, a cigarette vs. a cigarette case. If a word should apply to something only as part of a phrase (e.g., "cigarette" alone should never refer to the cigarette case) we can manage the situation as follows:

The case is a closed openable container. The printed name is "cigarette case". Understand "cigarette case" as the case.

Because "cigarette" here appears only as part of the phrase "cigarette case", it will be understood only in that context; the conflict with the bare cigarette will not arise.

As a variant, we may want one object only to take precedence over another in naming. If we wanted the player to be allowed to refer casually to the cigarette case as "cigarette" when (and only when) the cigarette itself is not in view, we could add

Understand "cigarette" as the case when the cigarette is not visible.

Tricks which consider the visibility of other objects can be bad for performance if used widely; but for adding finesse to the treatment of a few items, they work very well.

(There may still arise cases where the player uses a name which can legitimately refer to two different things in view. To deal with this situation, we may want the Does the player mean... rules, explained in the chapter on Understanding; and to change the way the story asks for clarification, see the two activities Asking which do you mean and Clarifying the parser's choice of something.)

Names of things which contain prepositions can also be tricky because Inform misreads the sentences creating them: Laura ★★ shows how some awkward cases can be safely overcome.

A more difficult case is to ensure that if we change the description or nature of something in play, then the names we understand for it adapt, too. "Understand... when..." can be all that's needed:

Understand "king" as Aragorn when we have crowned Aragorn.

Or, similarly, if we want some combination of categories and characteristics to be recognized:

Understand "giant" as a man when the item described is tall.

"The item described" here refers to the thing being named. "...when" can even be useful in defining new commands, and Quiz Show demonstrates how to ask open-ended questions that the player can answer only on the subsequent turn.

Properties can also be matched without fuss:

Tint is a kind of value. The tints are green, aquamarine and darkish purple. The wallpaper is fixed in place in the Hotel. The wallpaper has a tint. Understand the tint property as describing the wallpaper.

This allows EXAMINE AQUAMARINE WALLPAPER if, but only if, it happens to be aquamarine at the moment. Relationships can also be matched automatically:

A box is a kind of container. The red box is a box in the Toyshop. Some crayons are in the red box. Understand "box of [something related by containment]" as a box.

which recognises BOX OF CRAYONS until they are removed, when it reverts to plain BOX only.

Greater difficulty arises if, using some variable or property or table to mark that a bottle contains wine, we print messages calling it "bottle of wine". We are then honour-bound to understand commands like TAKE BOTTLE OF WINE in return, not to insist on TAKE BOTTLE. Almost all "simulation" IF runs in to issues like this, and there is no general solution because simulations are so varied.

A converse challenge arises when we want to avoid understanding the player's references to an object under some or all circumstances. This is relatively uncommon, but does sometimes occur. For this situation, Inform provides the "privately-named" property, as in

The unrecognizable object is a privately-named thing in the Kitchen.

Here "privately-named" tells Inform not to understand the object's source name automatically. It is then up to us to create any understand lines we want to refer to the object, as in

Understand "oyster fork" as the unrecognizable object when the etiquette book is read.

Of course, if we need an object that the player is never allowed to refer to at all, we can just make this privately-named and then not provide any understand lines at all.

A final source of difficulty is that by default Inform truncates words to nine letters before attempting to identify them. This is no problem in most circumstances and is likely to go unnoticed -- until we have two very long words whose names are nearly identical, such as "north-northwest exit" and "north-northeast exit". (To make matters worse, a punctuation mark such as a hyphen counts as two letters on its own.)

When we are compiling for Glulx, the limit is easily changed with a single line, setting the constant called DICT_WORD_SIZE. For instance, if we wanted to raise the limit to 15, we would write

Use DICT_WORD_SIZE of 15.

When compiling for the Z-machine, the solution is harder. North by Northwest ★★ shows how to use the reading a command activity to pre-process very long names, rendering them accessible to the parser again.

Inform also allows the player to refer to the most recently seen objects and people as IT, HIM, HER, and so on. It sets these pronouns by default, but there are times when we wish to override the way it does that. Pot of Petunias shows off a way to make Inform recognize an object as IT when it would not otherwise have done so.

See also

Liquids for a resolution of this bottle-of-wine issue
Using the Player's Input for an example (Mr. Burns' Repast) in which a fish can be called by any arbitrary word as long as it ends in the letters -fish
Memory and Knowledge for a way to refer to characters whom the player knows about but who aren't currently in the room
Clarification and Correction for ways to improve guesses about what the player means
Alternatives To Standard Parsing for several esoteric variations on the default behavior, such as accepting adverbs anywhere in the command, and scanning the player's input for keywords

Examples

11. First Name Basis

Sometimes we create objects that we want the player to be able to call by different names: a television that should also answer to "tv" and "telly", for instance, or a refrigerator the player might also call "fridge". In this case, we can use instructions like

Understand "tv" and "telly" as the television.

to add extra names to the object we've defined.

paste.png "First Name Basis"

The Crew Lounge is a room. "Deliberately spartan: the crew feels weight restrictions here first, so there aren't any chairs, just a few thin pads on the ground."

The holographic projector is a device in the Crew Lounge. "The one major source of entertainment is the holographic projector, a top of the line Misthon 9000, on which you view every beam you can get." Understand "holo" or "holograph" or "Misthon" or "9000" as the projector.

The description of the projector is "[if switched on]The projector is now playing a documentary about the early politics of the Mars colony.[otherwise]The air above the projector is disappointingly clear.[end if]".

(This description is for local color; we will learn more about devices, and conditions like "if switched on", later in this chapter.)

By default, Inform does not understand the names of an object's kind as referring to that object, unless the object has no other name of its own. We can change this, if we like, by defining names that should be applied to everything of a given kind:

Lewis and Harper are men in the Crew Lounge. Understand "man" or "guy" or "chap" or "lad" or "male" as a man. Understand "men" or "chaps" or "lads" or "guys" or "males" as the plural of a man.

The description of Lewis is "A wiry, excitable engineer who just signed aboard last week." The description of Harper is "Harper's a good guy: taciturn when sober, affectionate when drunk, but rarely annoying in either state."

Test me with "x holo / x man / lewis / x guy / harper / turn on projector / x holo projector / get men".

Inform's naming abilities go considerably further, in fact: we can also instruct it to understand words only under certain circumstances, or only when they appear with other words. Fuller details may be found in the chapter on Understanding.

323. Quiz Show

paste.png "Quiz Show" by Mike Tarbert

Use scoring.

Answer mode is a truth state that varies.
Current state is a text that varies.

Guessing is an action applying to one topic.
Understand "[text]" as guessing when answer mode is true.

Because of the "...when" part of this line, random text is only treated as an answer when a question is being asked.

Check guessing (this is the default wrong answer rule):
    if the topic understood is not a topic listed in the Table of Dates of Statehood:
        say "Wrong!";
    now answer mode is false.

Carry out guessing a topic listed in the Table of Dates of Statehood:
    if state entry is the current state:
        say "Correct! ([comment entry], to be exact!)";
        increase the score by one;
    otherwise:
        say "Wrong!";
    now answer mode is false.

This next rule allows a player to do something other than answer the question, but then makes him wait for another question before answering.

Before doing anything other than guessing:
    if answer mode is true:
        say "(ignoring the question)[line break]";
    now answer mode is false.

Section 2 - Scenario

The Lab is a room. Sam is a man in the lab.

Every turn when the player is in the lab:
    if a random chance of 3 in 5 succeeds:
        choose a random row in the Table of Dates of Statehood;
        say "Sam asks you, 'In what year was [state entry] admitted into the Union?'";
        now current state is state entry;
        now answer mode is true.

Table of Dates of Statehood

State

Topic

Comment

"Florida"

"1845"

"March 3rd"

"Delaware"

"1787"

"December 7th"

"Hawaii"

"1960"

"July 4th"

Test me with "1845 / z / z / 1787 / 1792 / z / 1845 / g".

Note that the situation will become a little more complicated if we have two or more identical topics in our trivia list; in that case, we would need to loop through the Table of Dates of Statehood explicitly, and only mark the player wrong if none of the lines were found to match. (See the chapter on Tables for many more ways to manipulate table behavior.)

325. Pot of Petunias

Suppose we have an object that makes a dramatic entrance on the scene, like so:

paste.png "Pot of Petunias"

Wide Open Field is a room. "A big field under a big sky. The clouds are puffy, the trees are handsome."

Some clouds and some trees are scenery in Wide Open Field. The description of the clouds is "That one looks like Yoda's head." The description of the trees is "You've never been much good at botany, so it's anyone's guess what kind they are."

A rock is in Wide Open Field. The description of the rock is "It looks like it's been here from the dawn of time."

The broken flower pot is a thing. The description of the broken flower pot is "It contains the remains of some abused petunias."

At 9:01 am:
    move the broken flower pot to the location;
    say "Quite unexpectedly, a flower pot falls from the sky and breaks open on the ground. Good thing you weren't standing six inches to the left.";
    set pronouns from the broken flower pot.

Test me with "x it / x it / x it".

If we leave out the "set pronouns..." line here, we'll wind up with the following very unsatisfactory end to our test transcript:

Quite unexpectedly, a flower pot falls from the sky and breaks open on the ground. Good thing you weren't standing six inches to the left.

>[3] x it
It looks like it's been here from the dawn of time.

19. Laura ★★

Occasionally it is useful to give something a printed name because we want to call it something extremely long-winded; give one thing a name that is the subset of the name of something else; or use words such as "with" or "and" that are likely to confuse Inform into thinking that the object name ends before it actually does.

Often it is enough to preface these ambiguously-titled things with "a thing called..." or "a supporter called..." or the like, as here:

South of Spring Rolls is a room called Hot and Sour Soup.

prevents Inform from trying to read "Hot and Sour Soup" as two separate rooms, while

The player carries an orange ticket. The player carries a thing called an orange.

creates two objects instead of the one orange ticket that would result if the second sentence were merely "The player carries an orange."

Really long names can be a bit cumbersome. For example:

The player carries a thing called an incriminating photograph of a woman with blonde hair.

So we might instead give the photograph a printed name:

paste.png "Laura"

The City of Angels is a room. The incriminating photograph is carried by the player. The printed name of the incriminating photograph is "incriminating photograph of a woman with blonde hair".

Now we've gotten around any awkwardness with printing the name -- but we also need to understand when the player refers to the photograph. When we define the names of objects under normal circumstances, Inform takes care of this automatically, but if we have especially set the printed name, we must also specially define the appropriate terms for the player to use. For this we need "understand", which will be explained in much more depth in a later chapter:

Understand "woman" or "with" or "blonde" or "hair" or "of" or "a" as the incriminating photograph.

Test one with "x photograph / x incriminating photograph of a woman with blonde hair / x hair / x blonde / x woman with blonde hair / x incriminating photograph of a woman".

That's probably as far as we really need to go, and if you are satisfied with this behavior, there is no need to read on.

One possible objection to this solution is that Inform will accept some nonsensical formulations as applying to the photograph: for instance, it will allow >EXAMINE PHOTOGRAPH OF, >X BLONDE PHOTOGRAPH WOMAN INCRIMINATING, or even >X OF ...though in the case there were two items with "of" names, the game would disambiguate with a question such as "Which do you mean, the incriminating photograph of a woman with blonde hair or the essence of wormwood?"

Traditionally, Inform has tended to be fairly flexible about word order, preferring to err in the direction of leniency. On the other hand, there are times when we need more exacting rules in order to distinguish otherwise similar cases.

Two features allow us to specify more exactly if we so desire. The first is that, if we specify a whole phrase as the name of something, all the words in that phrase are required, in the order given. Thus "Understand "blonde hair" as the photograph" would require that both "blonde" and "hair" be present, and would not recognize >X BLONDE, >X HAIR BLONDE, or >X HAIR.

Second, we can create tokens, such as "Understand "blonde hair" or "hair" as "[hair]", and then use these tokens in match phrases. This saves a good deal of time when we want to specify a number of different but fussy alternatives. So, for instance, here is a drawing that would not respond to >X OF, or >X BROWN EYES, but would respond to >X DRAWING OF MAN WITH BROWN EYES, >X MAN WITH BROWN EYES, and so on:

The drawing is carried by the player. The printed name of the drawing is "drawing of a man with brown eyes".

Understand "eyes" or "brown eyes" as "[brown eyes]". Understand "man" or "man with [brown eyes]" or "brown-eyed man" as "[man]". Understand "[man]" or "drawing of [man]" or "drawing of a [man]" as the drawing.

Test me with "test one / test two".

Test two with "x drawing / x man / x of / x drawing of man / x drawing of a man / x drawing of a man with brown eyes / x drawing of a brown-eyed man / x brown eyes".

Further refinements are possible: the "privately-named" attribute tells Inform not to try to understand the source name of an object at all, so if we write

The purple rabbit is a privately-named thing.

...the player will not be able to refer to it as "purple" or "rabbit" or "purple rabbit".

There are also ways to make names to refer to entire kinds of objects (so "dude" will refer to any man in the game); to specify names that only refer to objects in the plural (so GET PICTURES will pick up several pictures together); to reflect an object's properties (so "red apple" works only as long as the apple is in fact red); or even to refer to the object's relationships to other objects (so "bottle of wine" works only when wine is indeed in the bottle). All these refinements are discussed in the chapter on Understanding.

43. Vouvray ★★

The Understanding chapter lays out ways to change how the player can refer to objects, but we may not want to wait that long for some of the basic features. Here, for instance, is how to add synonyms that the player can use to refer to an entire kind of object:

paste.png "Vouvray"

The Wine Emporium is a room. "Set aside, you rather suspect, for tourists: this chamber is barrel-vaulted stone, lined on each side with casks of aging wine. Discarded brochures here and there advertise Wine Tours of the Loire Valley in three different languages, none of them French."

A cask is a kind of thing. A cask is always fixed in place. Understand "cask" or "barrel" as a cask. Understand "casks" or "barrels" as the plural of cask.

The Vouvray cask and the Muscadet cask are casks in the Wine Emporium.

Test me with "get barrels / get barrel / muscadet / x casks / x muscadet cask".

374. North by Northwest ★★

Suppose we wanted to add intermediate compass directions such as north-northwest to our game. Because of the limitations of the index map, we won't be able to view these connections on the world map, but we can certainly create them, and use them in route-finding, just like other directions.

Here's how we'd set up such a thing:

paste.png "North by Northwest"

Section 1 - Procedure

The north-northwest is a direction. North-northwest has opposite south-southeast. Understand "n-nw" or "nnw" as north-northwest.

The north-northeast is a direction. North-northeast has opposite south-southwest. Understand "n-ne" or "nne" as north-northeast.

The south-southwest is a direction. South-southwest has opposite north-northeast. Understand "s-sw" or "ssw" as north-northwest.

The south-southeast is a direction. South-southeast has opposite north-northwest. Understand "s-se" or "sse" as south-southeast.

The west-northwest is a direction. West-northwest has opposite east-southeast. Understand "w-nw" or "wnw" as west-northwest.

The east-northeast is a direction. East-northeast has opposite west-southwest. Understand "e-ne" or "ene" as east-northeast.

The west-southwest is a direction. West-southwest has opposite east-northeast. Understand "w-sw" or "wsw" as west-northwest.

The east-southeast is a direction. East-southeast has opposite west-northwest. Understand "e-se" or "ese" as east-southeast.

A complication arises because we reach the 9-character limit: Inform truncates the names of objects to nine characters before trying to understand them. To make matters worse, the hyphen (and other punctuation marks) count as two letters. So both north-northwest and north-northeast will get truncated to "north-no", and be indistinguishable when the player types them.

When we are compiling for Glulx, the limit is easily changed with a single line, setting the constant called DICT_WORD_SIZE. For instance, if we wanted to raise the limit to 15, we would simply write "Use DICT_WORD_SIZE of 15."

If we're compiling to the Z-machine, however, we'll have to resort to some manipulation of the player's command. The general solution is that when the player's name for an object is going to have to be longer than we can correctly read, we can substitute an unambiguous abbreviation for the thing the player typed. In this case, it will be simplest and most efficient always to condense the player's direction names to single letters, thus:

After reading a command:
    let N be "[the player's command]";
    replace the text "north" in N with "n";
    replace the text "east" in N with "e";
    replace the text "south" in N with "s";
    replace the text "west" in N with "w";
    change the text of the player's command to N.

For more on the use of text, see the Advanced Text chapter.

Section 2 - Scenario

The Empty Field is north-northwest of the Deserted Road.

A crop-dusting plane is a backdrop. It is not scenery. It is in the Deserted Road and Empty Field. The initial appearance of the crop-dusting plane is "[one of]In the distance[or]Approaching faster and faster[or]Flying ominously low and directly towards you[or]Immediately overhead[or]Circling around for another approach[cycling] is a standard crop-dusting plane."

After looking:
    say "From here you can run to [the list of adjacent rooms]."

Rule for printing the name of a room (called the target) which is not the location while looking:
    let chosen direction be the best route from the location to the target;
    say "[chosen direction]".

Test me with "sse / north-northwest".

In practice, this is going to be overkill for almost all games: most players already find eight compass directions plus up and down to be enough (or more than enough) to keep track of. But the option exists, in case there is a compelling reason to use it.

(Note also that we are allowed to use multi-word direction names, so we could have called the directions "north by northwest", "north by northeast", and so on. This example deliberately takes the hard way in order to show how to resolve the nine-character problem.)

RB §2.3. Using the Player's Input

We may sometimes want to capture specific words the player has used and then feature that text elsewhere in the story.

Terracottissima Maxima ★★★ demonstrates using text to describe objects; Mr. Burns' Repast ★★ lets the player refer to a fish by any of a number of names, and changes the way the fish is described as a result.

More specialized effects are also possible: Xot ★★★ shows how to collect the player's erroneous input and store the command line to be printed back later. Igpay Atinlay shows how to parrot the player's command back in pig Latin form.

See also

Animals for a dog which the player can re-name
Traits Determined By the Player for a way to let the player name the player character

Examples

419. Igpay Atinlay

For the sake of argument, suppose we want to parrot back all the player's commands in pig Latin:

paste.png "Igpay Atinlay"

Armfay is a room.

After reading a command:
    let N be "[the player's command]";
    replace the regular expression "\b(<aeiou>+)(\w*)" in N with "\1\2ay";
    replace the regular expression "\b(<bcdfghjklmnpqrstvwxz>+)(\w*)" in N with "\2\1ay";
    say "[N][paragraph break]";
    reject the player's command.

Test me with "nix on the stupid".

423. Mr. Burns' Repast ★★

Suppose we have an unhappily mutated fish that the player can refer to by any of a number of species names, or any word followed by -fish. We want to reject these commands, but preserve a memory of what the player last tried to call the thing:

paste.png "Mr. Burns' Repast"

Wharf is a room.

There is an unknown fish in the Wharf. The unknown fish has some a text called the supposed name. The description of the unknown fish is "The victim of heavy mutagens, this thing is not really recognizable as any species you know.".

Fish variety is a kind of value. The fish varieties are salmon, albacore, mackerel.

Rule for printing the name of the unknown fish:
    if the supposed name of the unknown fish is "", say the printed name of the unknown fish;
    otherwise say the supposed name of the unknown fish.

After reading a command:
    if the unknown fish is visible and player's command matches the regular expression "\b\w+fish":
        let N be "[the player's command]";
        replace the regular expression ".*(?=\b\w+fish)" in N with "";
        now N is "[N](?)";
        now the supposed name of the unknown fish is N;
        respond with doubt;
        reject the player's command;
    otherwise if the unknown fish is visible and the player's command includes "[fish variety]":
        now supposed name of the fish is "[fish variety understood](?)";
        respond with doubt;
        reject the player's command.

To respond with doubt:
    say "You're not [italic type]sure[roman type] you're seeing any such thing."

Test me with "get swordfish / look / touch monkfish / look / listen to tunafish / x fish / x salmon / look".

318. Terracottissima Maxima ★★★

Inform can also understand text properties:

paste.png "Terracottissima Maxima"

A flowerpot is a kind of thing. A flowerpot has a text called pattern. Understand the pattern property as describing a flowerpot. The printed name of a flowerpot is usually "[pattern] flowerpot". The printed plural name of a flowerpot is usually "[pattern] flowerpots".

The Herb Garden is a room. In the Herb Garden is a flowerpot with pattern "blue willow". In the Herb Garden is a flowerpot with pattern "striped". In the Herb Garden is a flowerpot with pattern "striped".

Test me with "x blue willow / get striped / look".

This may not seem very much different from having the pattern be a kind of value -- except that texts can, of course, hold almost anything. Further exploration of these possibilities may be found in the chapter on Advanced Text.

381. Xot ★★★

In Hitchhiker's Guide to the Galaxy, any erroneous command the player types can return to haunt him later in the game. We could do the same, if we liked, by storing the player's command whenever we print a parser error.

paste.png "Xot"

Humiliation Chamber is a room. "A grim, grey-walled room. Cameras watch you from every angle; convex mirrors reflect your actions; and up near the ceiling, where you can't disable it, is a loudspeaker."

The last error is a text that varies. The last error is "xot".

Before printing a parser error:
    now the last error is the player's command.

Every turn when a random chance of 1 in 2 succeeds:
    say "Over the loudspeaker comes some distorted nonsense. If you listen carefully, it sounds as though some fool is saying '[last error], [last error], [last error]!'"

Test me with "wiggle / z / z / z / z / z / z".