14. Adaptive Text and Responses

Writing with Inform

WI §14.1 Tense and narrative viewpoint

A conspicuous difference between interactive fiction and a traditional novel is the point of view from which it's told. Inform usually produces text like:

You can see a grey cat in the basket.

where a novel would usually write:

He saw a grey cat in the basket.

Standard interactive fiction (IF) is second person singular, and present tense; most novels are told in the third person singular, and past tense.

But these are just conventions – a few novels, for example, use the so-called present historic ("Napoleon looks up at the sky and sighs. Must Ney always be so doubting?"), and plenty are told in the first person singular ("I always get the shakes before a drop."). Inform allows some of this flexibility, too. The two values:

story viewpoint
story tense

control the style of the text produced. The story viewpoint has to be one of the values:

first person singular
second person singular
third person singular
first person plural
second person plural
third person plural

(which are actually the six possible values of a kind called "narrative viewpoint"), while the story tense must be one of:

past tense
present tense
future tense
perfect tense
past perfect tense

(from a kind called "grammatical tense"). Combining these gives 30 possibilities in all, though only a few are at all commonly used.

It's important to make a very large caveat here: Inform uses these settings in producing the replies ("responses") by the built-in actions, but the only way for all of our own text to have a particular tense or narrative viewpoint is to write it that way. If we write:

The Taj Mahal is a room. "You stand and admire the Taj Mahal."
When play begins:
   now the story viewpoint is first person plural;
   now the story tense is past tense.

then we're likely to see the following peculiar transcript:

Taj Mahal
You stand and admire the Taj Mahal.
>e
We couldn't go that way.

That's because the response ("We couldn't go that way") was constructed to follow the settings for viewpoint and tense, but the fixed text of the room description wasn't. In fact there are ways to write the room description so that it would adapt itself automatically, as we'll see, but it takes a fair amount of work. More simply:

The Taj Mahal is a room. "I stood and admired the Taj Mahal."
When play begins:
   now the story viewpoint is first person plural;
   now the story tense is past tense.

In short, tense and viewpoint switching is neat, but it isn't magic.

If we want to write text which will work in whatever the current tense is, the following turn out to be useful little conveniences:

say "[here]"

Produces "here" if the story tense is the present tense, and "there" otherwise.

say "[now]"

Produces "now" if the story tense is the present tense, and "then" otherwise.

WI §14.2 Adaptive text

Paying attention to the tense and viewpoint is one reason why text might need to adapt. Another is that it might need to adapt according to whether nouns are singular or plural, or whether it talks about the player or some third party. For example, the following rule isn't ideal:

Instead of taking: say "[The noun] is pinned down by Dr Zarkov's force field."

Most of the time it's fine ("The V-ray is pinned down by Dr Zarkov's force field"), but then:

> GET ME
You is pinned down by Dr Zarkov's force field.
> GET CONDENSERS
The condensers is pinned down by Dr Zarkov's force field.

Which is a little unfortunate. But the correction is very easy:

Instead of taking: say "[The noun] [are] pinned down by Dr Zarkov's force field."

The result is much better: "The V-ray is pinned down…"; "You are…"; "The condensers are…". In fact, it's also convenient because it adapts to the story viewpoint and story tense: "The condensers will be pinned down…"; "He was pinned down…".

How does Inform do this? The answer is not that "[are]" is a specially-written text substitution. In fact Inform can do this with any verb that it has a definition of. For example,

"[The noun] [carry] too much static charge."

would also adapt itself – "The V-ray carries too much static charge", and so on. There aren't many verbs built in to Inform, but "[have]" and "[carry]" and "[wear]" and "[can]" may be useful, and "[can see]" and "[can touch]". Negative forms like "[are not]" are also available:

"[The noun] [cannot touch] the ionizer terminal."

might produce "The V-ray will not be able to touch the ionizer terminal.", for example.

As these examples hint, the verb adapts itself to the most recently printed object name. All of this only works if the previous object's name is printed from a substitution. So:

"[The condensers] [are] working."

will work – correctly forming "The condensers are working.", "The condensers will be working." or "The condensers were working.", according to the story tense – but

"The condensers [are] working."

probably won't work. Inform doesn't have any way to understand the raw text outside of the text substitution marks "[" and "]", and it doesn't recognise "The condensers" as being something's name.

Something else to be careful with is the use of lists. If we write this:

"[The condensers] and [the V-ray] [are] smashed by Voltan's birdmen."

then Inform is likely to print:

The condensers and the V-ray is smashed by Voltan's birdmen.

because it looks at the most recently named object – the V-ray, singular – to decide whether to use "is" or "are". On the other hand, Inform gets this right:

"[The list of things on the bench] [are] smashed by Voltan's birdmen."

Because Inform constructs the list itself, it's able to appreciate that the things listed are jointly the subject of the verb, and it uses that information to decide on "is" or "are". So:

The condensers and the V-ray are smashed by Voltan's birdmen.
The Atomic Furnace shovel is smashed by Voltan's birdmen.

WI §14.3 More on adapting verbs

If we need an adaptive message with a verb which doesn't belong to Inform's built-in set, all we need do is define it. In the previous chapter we defined verbs by giving them meanings, but in fact that's optional. For example:

To retrofit is a verb.

defines a verb without telling Inform what it means. Inform will throw a Problem message if we try to write text like:

Flash retrofits the meteor beam.

because, after all, it doesn't know what "retrofit" means. But it does still know how to print it, so this works:

"[The actor] [retrofit] the Mecha-Mole."

which might come out as "Dale retrofits the Mecha-Mole", or "Barin's archers retrofitted the Mecha-Mole", and so on.

This is especially neat for writing a single response to an action which works regardless of who the actor was. For example, the Standard Rules include:

say "[The actor] [put] [the noun] on [the second noun]."

And this can make either:

You put the revolver on the table.
General Lee puts the revolver on the table.

Examples

Creating dynamic room descriptions that contain sentences such as "Clark is here, wasting time" or "Clark is here, looking around" depending on Clark's idle activity.
246.
Variety ★★
Suppose we want all of our action responses to display some randomized variety. We could do this by laboriously rewriting all of the response texts, but this example demonstrates an alternative.
247.
Variety 2 ★★
This builds on the Variety example to add responses such as "You are now carrying the fedora" that describe relations that result from a given verb, as alternate responses.
248.
Suppose we want all of our action responses to vary depending on some alterable quality of the narrator, so that sometimes they're slangy, sometimes pompous or archaic.

WI §14.4 Adapting text about the player

In second-person-singular IF, the player is always "you". Many messages look like so:

"You have twenty minutes remaining."

where the subject, or the object, of the sentence is "you". But what if we want to have this text adapt itself to different narrative viewpoints?

The solution is to use the following:

"[We]" or "[we]"
"[Us]" or "[us]"
"[Our]" or "[our]"
"[Ours]" or "[ours]"
"[Ourselves]" or "[ourselves]"

The capitalised and uncapitalised versions are identical except, of course, that the initial letter of the resulting text is upper case in one but not the other. As examples of these:

"[We] [carry] the Queen's warrant."
"The birds drop pebbles on [us]. Right on [our] heads!"
"[Ours] are the burdens of office, which [we] take on [ourselves]."

Notice that all five of these forms are differently worded, in English. That's the reason why we use the plural to write them – the traditional second person plural forms would be "you", "you", "your", "yours" and "yourself", so we wouldn't know if "[you]" was supposed to be the subject or the object of the verb. So the convention with all of these adaptive forms is that we use "we" and its variations. (That's also why the verbs are written in the plural – "[carry]", not "[carries]".)

WI §14.5 Adapting text referring to other things

The family in the previous section – "[we]", "[us]", "[our]", "[ours]", "[ourselves]" – always referred to the player. But we also sometimes want to refer to other things without naming them. For example, how should we adapt this?

> EXAMINE TREE
It has no clear outline in this misty netherworld.

We can easily make the verb adapt – change the "has" to "[have]" – but the trick here is to make the "It" adapt to cases where what's examined is plural, or animate. What we want is:

Instead of examining in the Netherworld:
   say "[regarding the noun][They] [have] no clear outline in this misty netherworld."

For example, this produces:

> EXAMINE ME
You have no clear outline in this misty netherworld.
> EXAMINE MARK
He has no clear outline in this misty netherworld.
> EXAMINE DRUMS
They have no clear outline in this misty netherworld.

Note that we have to say "[regarding the noun]", not just start in with "[They]", because nothing has been named so far in the sentence – so Inform doesn't know what object it refers to. "[regarding the noun]" prints nothing, and simply tells the printing part of Inform that the subject has changed.

This isn't always needed:

"[We] [have] a look at [the noun], but [they] [are] just too big."

works fine, because printing "[the noun]" changes the subject to that, and then "[they]" agrees with it automatically. The text might come out, for example, as:

I had a look at Peter Rabbit, but he was just too big.
You have a look at the chessmen, but they are just too big.
We have a look at ourselves, but we are just too big.

We have a family of five text substitutions here, matching those in the previous section:

"[They]" or "[they]"
"[Them]" or "[them]"
"[Their]" or "[their]"
"[Theirs]" or "[theirs]"
"[Themselves]" or "[themselves]"

There's also the peculiar impersonal non-object for English sentences like "It is raining" or "There are books":

"[It]" or "[it]"
"[There]" or "[there]"

These look pointless – but consider the two texts

"[We] [take] [the noun]. It [rain] harder."
"[We] [take] [the noun]. [It] [rain] harder."

The first one risks printing "We took the scissors. It rain harder.", because it makes "[rain]" agree with "scissors", which are plural. But the second text makes "[rain]" agree with "[it]". And, as a convenience:

"[It's]" or "[it's]"
"[There's]" or "[there's]"

do the obvious thing using the current story tense.

Finally, we occasionally want to agree with a number:

"Honestly, [dud count][regarding the dud count] of these [are] broken."

WI §14.6 Adapting demonstratives and possessives

Consider the following message: how might we make this adaptive?

> MEASURE TOP SHELF
You really are not tall enough to reach that.

The verbal part is easy enough, but "that" needs a new feature.

"[We] really [are not] tall enough to reach [regarding the noun][those]."

This could then adapt to, say,

> MEASURE JAM TARTS
He really was not tall enough to reach those.

Notice that it's "[regarding the noun][those]", not just "[those]". If we wrote "[those]", Inform would make it agree with the player, who was printed earlier in the sentence by the "[We]".

Lastly, how about:

> PUT TEAPOT IN MOUSEHOLE
The teapot's height is just too great.

This time we want:

"[regarding the noun][Possessive] height [are] just too great."

which might adapt to, say,

Our height is just too great.
Alice's height will be just too great.

Actually, "[regarding …]" can be used for a description of possibly many items, too. For example:

Every turn when the player carries something:

say "Every possession is a worry. I wonder if [regarding things carried by the player][they] still [look] okay in your pocket?"

So if the player carries just a single coin, say, this automatically becomes:

Every possession is a worry. I wonder if it still looks okay in your pocket?

but if the player carries a pair of scissors (a single plural-named item) or a coin and an iPhone, it becomes:

Every possession is a worry. I wonder if they still look okay in your pocket?

Once again these text substitutions are available in capitalised and uncapitalised forms:

"[Those]" or "[those]"
"[Possessive]" or "[possessive]"

In fact "[Those]" and "[those]" do subtly different things, besides the capital letter, because "[Those]" expects to be the subject of the sentence and "[those]" the object, and this makes a difference if the noun in question is a person. If the noun is an odious person called Tilly then

"[regarding the noun][Those] is unacceptable."
"You've never liked [regarding the noun][those]."

would come out as "She is unacceptable" – so "[Those]" becomes "She" – but "You've never liked her" – so "[those]" becomes "her". If we need these in different cases, we can explicitly ask for that:

"[those in the nominative]"
"[Those in the accusative]"

Example

Some adaptive text for smelling the flowers, or indeed, anything else.

WI §14.7 Can, could, may, might, must, should, would

English uses so-called "modal verbs" to change a sentence so that it talks about something only possibly happening. For example, the sentence "Fred goes to school" can be modified to "Fred must go to school", "Fred should go to school" or even "Fred might go to school".

Inform supports the use of modal verbs in text substitutions. For example,

"[Fred] [might go] to school."

would in the present tense come out as "Fred might go to school.", but could alternatively be "Fred might have gone to school." As this example shows, all that's needed is to take a verb we'll call V – this case, "go" – and we can write any of these:

"[can V]" or "[cannot V]" or "[can't V]"
"[could V]" or "[could not V]" or "[couldn't V]"
"[may V]" or "[may not V]" or "[mayn't V]"
"[might V]" or "[might not V]" or "[mightn't V]"
"[must V]" or "[must not V]" or "[mustn't V]"
"[should V]" or "[should not V]" or "[shouldn't V]"
"[would V]" or "[would not V]" or "[wouldn't V]"

That helps us to handle informal usages like this one:

"You can't go that way."

To make this message adaptive, we write:

"[We] [can't go] that way."

which can adapt in surprising ways – "They won't be able to go that way.", for example.

Note that the verb V has to be one that Inform knows. But that's easy:

To discombobulate is a verb.

and then

"[Fred] [might not discombobulate] so easily."

could produce "Fred might not have discombobulated so easily", for example.

WI §14.8 Adapting contractions

Contractions usually take the form of part of a word being missed out and replaced by an apostrophe. We've already seen "[can't]", "[couldn't]", "[mayn't]", "[mightn't]", "[mustn't]", "[shouldn't]" and "[wouldn't]", for example. But Inform supports other contractions, too, as follows.

The English verbs "to be" and "to have" are unique in having contracted forms, which we can write "['re]" and "['ve]", like this:

"[We]['ve] got rhythm. [We]['re] cool."

which might produce, say, "I've got rhythm. I'm cool.", or "He'll have rhythm. He'll be cool.", or "You had got rhythm. You were cool." (The contractions don't appear in the past tense; but the spacing fixes itself automatically.)

The Standard Rules often use a special text substitution for responses like this one:

"[They're] hardly portable."

This is exactly like "[Those]['re] hardly portable" except that if the plural is needed, Inform prints "They're hardly portable" rather than the correct, but not quite idiomatic, "Those're hardly portable". (If we wrote "[They]['re] …", that would get the plural form right, but then the singular would be "It's hardly portable" not "That's hardly portable".)

Only a few English verbs have contracted negative forms, beyond those already mentioned. Inform knows these informal forms:

"[aren't]"
"[don't]"
"[haven't]"
"[won't]"

For example,

Instead of taking something:
   say "[The noun] [are] pinned down by Dr Zarkov's force field. [They] [aren't] free to move. [They] [can't] move. [They] [won't] move. [They] [haven't] a chance to move. Anyhow, [they] [don't] move."

can produce variations like these:

The condensers are pinned down by Dr Zarkov's force field. They aren't free to move. They can't move. They won't move. They haven't a chance to move. Anyhow, they don't move.
You were pinned down by Dr Zarkov's force field. You weren't free to move. You couldn't move. You wouldn't move. You hadn't a chance to move. Anyhow, you didn't move.

WI §14.9 Verbs as values

Each verb known to Inform is actually a value of the kind "verb". To refer to a verb as a value, we have to put the word "verb" in front, as in these examples:

the verb contain, the verb might, the verb provoke

all of which appear in the Standard Rules.

Two adjectives are provided for use with verbs: "modal" (or "non-modal") to pick out verbs like might, could, should, and so on; and "meaningful" (or "meaningless") to pick out verbs which have a defined meaning as an Inform relation. For example, in the Standard Rules, the verb contain is meaningful, the verb might is modal, and the verb provoke is meaningless.

If V has a meaning as a relation of objects, then "meaning of V" produces that relation. For example,

showme the meaning of the verb contain;
showme the meaning of the verb provoke;

produces:

"meaning of the verb contain" = relation of objects: containment relation
"meaning of the verb provoke" = relation of objects: equality relation

As this demonstrates, if a verb has no meaning, or its meaning doesn't relate to objects, we get just the equality relation.

In fact, Inform even defines a verb "to mean": it's meaningful, and its meaning is the meaning relation. Thus:

if the verb mean means the meaning relation...

is true. More usefully, we can search our vocabulary like this:

the list of verbs meaning the containment relation

which, unless any non-Standard Rules definitions have been added, produces:

list of verbs: {verb contain}

Note that the meaning relation can't be changed at run-time: it is not clear what it would even mean to do something like -

now the verb contain means the wearing relation;

with the story already started, so this will produce a problem message.

say "[adapt (verb)]"

Adapts the given verb to the current story tense and story viewpoint. For example, "you [adapt the verb provoke]" might produce "you provoke".

say "[adapt (verb) from (narrative viewpoint)]"

Adapts the given verb to the current story tense but the given viewpoint. For example, "he [adapt the verb provoke from the third person singular]" might produce "he provokes".

say "[adapt (verb) in (grammatical tense)]"

Adapts the given verb to the given tense but the current story viewpoint. For example, "you [adapt the verb provoke in the past tense]" might produce "you provoked".

say "[adapt (verb) in (grammatical tense) from (narrative viewpoint)]"

Adapts the given verb to the given tense and viewpoint. For example, "we [adapt the verb provoke in the future tense from the first person plural]" might produce "we will provoke".

say "[negate (verb)]"

Adapts the given verb to the current story tense and story viewpoint, giving it a negative sense. For example, "you [negate the verb provoke]" might produce "you do not provoke".

say "[negate (verb) from (narrative viewpoint)]"

Adapts the given verb to the current story tense but the given viewpoint, giving it a negative sense. For example, "he [negate the verb provoke from the third person singular]" might produce "he does not provoke".

say "[negate (verb) in (grammatical tense)]"

Adapts the given verb to the given tense but the current story viewpoint, giving it a negative sense. For example, "you [negate the verb provoke in the past tense]" might produce "you did not provoke".

say "[negate (verb) in (grammatical tense) from (narrative viewpoint)]"

Adapts the given verb to the given tense and viewpoint, giving it a negative sense. For example, "we [negate the verb provoke in the future tense from the first person plural]" might produce "we will not provoke".

Note that the verb doesn't have to be named explicitly for use by the adapt or negate phrases, so for example:

To decide which text is the rendering of (V - verb) (this is my rendering):
   decide on "[negate V in the past perfect tense]".
When play begins:
   showme my rendering applied to the list of meaningful verbs.

produces:

"my rendering applied to the list of meaningful verbs" = list of texts: {"had not had", "had not related", "had not meant", "had not provided", "had not contained", "had not supported", "had not incorporated", "had not enclosed", "had not carried", "had not held", "had not worn", "had not been able to see", "had not been able to touch", "had not concealed", "had not unlocked"}

Lastly, we can get at three other useful parts of a verb, too. These aren't adaptive, of course: a verb only has one infinitive form.

say "[infinitive of (verb)]"

Verbs are sayable values, but if you were to say "[verb carry]" it would be "verb carry". The infinitive of phrase omits the "verb", so you get the infinitive of the given verb but without "to". So say "[infinitive of verb carry]" produces just "carry".

say "[past participle of (verb)]"

Produces the past participle of the given verb. For example, "[past participle of the verb carry]" is "carried". Warning: because modal verbs like "should" or "might" are defective in English, this will produce odd results on them – "shoulded" and "mighted", for example.

say "[present participle of (verb)]"

Produces the present participle of the given verb. For example, "[present participle of the verb carry]" is "carrying". Warning: because modal verbs like "should" or "might" are defective in English, this will produce odd results on them – "shoulding" and "mighting", for example.

Examples

250.
We create phrases such as "the box we took" and "the newspaper Clark looked at" based on what has already happened in the story.
An example of how to create room descriptions that acknowledge particular relations using their assigned verbs, rather than by the heavily special-cased code used by the standard library.

WI §14.10 Responses

Most of the text which the player sees is drawn from the source, but mixed in with this are messages apparently added by Inform itself – usually in the form of short sentences saying that something has been done, or that something can't be done. Such pieces of text are called "responses", because they are almost always replies to commands. For example:

> EAST
You can't go that way.
> JUMP
You jump on the spot.

Responses like this, which don't appear anywhere in the source text, come from one of the extensions being used; most often from the Standard Rules, the "extension" which is automatically included in every project. The SR contain many small rules, and almost all of these are capable of producing one or two standard responses. These are labelled with the rule's name and then a bracketed letter – (A), (B), (C), … as needed so that every response has its own unique name. There's nothing very mysterious about how this is done. For example, here is a rule with one response:

Carry out taking inventory (this is the print empty inventory rule):
   if the first thing held by the player is nothing,
      say "[We] [are] carrying nothing." (A) instead.

which makes the familiar text "You are carrying nothing." a response named:

print empty inventory rule response (A)

These names are actually values, belonging to the kind "response". Because of that, if we try this:

say "Hmm: [print empty inventory rule response (A)]"

Inform will produce

Hmm: print empty inventory rule response (A)

since we gave Inform a value to print, and that's just what it then did. As an alternative:

say "[text of (response)]"

This text substitution writes out the current text of the given response.

Thus,

say "Hmm: [text of print empty inventory rule response (A)]"

produces

Hmm: You are carrying nothing.

WI §14.11 Changing the text of responses

These responses are named so that they can be changed. Most IF authors dislike one or two of the existing responses, and some would like to change almost all of them to give the text a different style; and extensions for IF in languages other than English change literally every response, of course.

It's very easy to change responses:

The print empty inventory rule response (A) is "Your hands are, like, totally empty. Lame."

and we can even do this dynamically during play:

now the print empty inventory rule response (A) is "Your hands ...";

just as if we were setting a variable.

Example

252.
Altering the standard inventory text for when the player is carrying nothing.

WI §14.12 The RESPONSES testing command

In practice we can't change these responses unless we know what they're called. One way to find out is just to read through the extensions we're using, but that's a laborious process. A more practical answer is to type:

> RESPONSES

which replies by listing the sets of responses currently available; for example, it says that RESPONSES 1 is the set of responses for the Standard Rules. We can then type exactly that:

> RESPONSES 1
Standard Rules:
   block vaguely going rule response (A): "You'll have to say which compass direction to go in."
   print the final prompt rule response (A): "> [run paragraph on]"
   ...

and so on. This lists all of the responses, rule by rule, along with their current texts.