Chapter 2: Adaptive Prose

§2.1. Varying What Is Written; §2.2. Varying What Is Read; §2.3. Using the Player's Input

arrow-up-left.pngContents of The Inform Recipe Book
arrow-left.pngChapter 1: How to Use The Recipe Book
arrow-right.pngChapter 3: Place
arrow-down-right.pngIndexes of the examples

§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.


arrow-up.pngStart of Chapter 2: Adaptive Prose
arrow-left.pngBack to Chapter 1: How to Use The Recipe Book: §1.4. Information Only
arrow-right.pngOnward to §2.2. Varying What Is Read

*ExampleFifty Ways to Leave Your Larva
Using text substitution to make characters reply differently under the same circumstances.

*ExampleAhem
Writing a phrase, with several variant forms, whose function is to follow a rule several times.

*ExampleNumberless
A simple exercise in printing the names of random numbers, comparing the use of "otherwise if...", a switch statement, or a table-based alternative.

*ExampleM. Melmoth's Duel
Three basic ways to inject random or not-so-random variations into text.

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

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

*ExampleProlegomena
Replacing precise numbers with "some" or other quantifiers when too many objects are clustered together for the player to count at a glance.

*ExampleWesponses
Parser messages that are delivered with a speech impediment.

*ExampleRocket Man
Using case changes on any text produced by a "to say..." phrase.

*ExampleBlackout
Filtering the names of rooms printed while in darkness.

*ExampleCurare
A phrase that chooses and names the least-recently selected item from the collection given, allowing the text to cycle semi-randomly through a group of objects.

*ExampleBlink
Making a "by atmosphere" token, allowing us to design our own text variations such as "[one of]normal[or]gloomy[or]scary[by atmosphere]".

**ExampleVariety 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.

**ExampleVariety
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.

**ExampleFun with Participles
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.

**ExampleHistory Lab
We create phrases such as "the box we took" and "the newspaper Clark looked at" based on what has already happened in the story.

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.

**ExampleRelevant Relations
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.

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.

***ExampleBallpark
A new "to say" definition which allows the author to say "[a number in round numbers]" and get verbal descriptions like "a couple of" or "a few" as a result.

***ExampleFifty Times Fifty Ways
Writing your own rules for how to carry out substitutions.

***ExampleNarrative Register
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.

***ExampleStraw Into Gold
Creating a Rumpelstiltskin character who is always referred to as "dwarf", "guy", "dude", or "man" -- depending on which the player last used -- until the first time the player refers to him as "Rumpelstiltskin".