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.

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

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

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

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

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

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