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
000.
Using text substitution to make characters reply differently under the same circumstances.
000.
Writing a phrase, with several variant forms, whose function is to follow a rule several times.
000.
A simple exercise in printing the names of random numbers, comparing the use of "otherwise if…", a switch statement, or a table-based alternative.
000.
Three basic ways to inject random or not-so-random variations into text.
000.
Some adaptive text for smelling the flowers, or indeed, anything else.
000.
Altering the standard inventory text for when the player is carrying nothing.
000.
Replacing precise numbers with "some" or other quantifiers when too many objects are clustered together for the player to count at a glance.
000.
Parser messages that are delivered with a speech impediment.
000.
Using case changes on any text produced by a "to say…" phrase.
000.
Filtering the names of rooms printed while in darkness.
000.
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.
000.
Making a "by atmosphere" token, allowing us to design our own text variations such as "[one of]normal[or]gloomy[or]scary[by atmosphere]".
000.
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.
000.
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.
000.
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.
000.
We create phrases such as "the box we took" and "the newspaper Clark looked at" based on what has already happened in the story.
000.
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.
000.
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.
000.
Writing your own rules for how to carry out substitutions.
000.
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.
000.
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".
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 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.)
See Also
Liquids for a resolution of this bottle-of-wine issue.
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
000.
Allowing the player to use different synonyms to refer to something.
000.
In this example by Mike Tarbert, the player can occasionally be quizzed on random data from a table; the potential answers will only be understood if a question has just been asked.
000.
Responding sensibly to a pot of petunias falling from the sky.
000.
Some general advice about creating objects with unusual or awkward names, and a discussion of the use of printed names.
000.
Adding synonyms to an entire kind of thing.
000.
Creating additional compass directions between those that already exist (for instance, NNW) -- and dealing with an awkwardness that arises when the player tries to type "north-northwest". The example demonstrates a way around the nine-character limit on parsed words.