Chapter 2: Adaptive Prose
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. Odins carefully avoids a giveaway grammatical blunder - the kind only a computer would make. 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.

A few of Inform's included extensions provide extra control over text output, as well: Complex Listing allows us more control over the order and presentation of lists of items, and Plurality provides functions for handling pronouns and objects whose names might be understood as singular or plural.

The extension Case Management used to be used for changing the case of something printed, but it is now included chiefly to support older Inform projects: now the best way to change printed text to upper, lower, sentence, or title casing is to use indexed text, as demonstrated in Rocket Man.


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

WI
169
* Example  Ahem
Writing a phrase, with several variant forms, whose function is to follow a rule several times.

WI
71
* Example  Fifty Ways to Leave Your Larva
Using text substitution to make characters reply differently under the same circumstances.

WI
72
*** Example  Fifty Times Fifty Ways
Writing your own rules for how to carry out substitutions.

WI

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:

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

428
* Example  Curare
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.

WI
294
*** Example  Straw 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".

WI
440
* Example  Odins
Making [is-are] and [it-they] say tokens that will choose appropriately based on the last object mentioned.

WI
60
*** Example  Ballpark
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.

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

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

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

WI
408
* Example  Blackout
Filtering the names of rooms printed while in darkness.

WI
401
* Example  Rocket Man
Using case changes on any text produced by a "to say..." phrase.

WI


PreviousContentsNext