16.22. Review of Chapter 16: Understanding

| Chapter 16: Understanding |

| 16.22. Review of Chapter 16: Understanding

"Understand..." rules are used in Inform to change both how the player can give commands (such as POLISH THE SILVER) and how the player is allowed to refer to individual objects.

1. Understanding the names of things. As we've seen since the earliest chapters, we may add to the vocabulary used to refer to an object in the game, or to an entire class:

> Understand "fish" as the trout.
> Understand "fish" or "dinner" as the trout.
> Understand "fish/dinner" as the trout.
> Understand "gentleman" as a man.

If we use an entire phrase, as here

> Understand "red bird" as the robin.

Inform will match only the full phrase and not its components; so EXAMINE RED BIRD would work, but not EXAMINE RED or EXAMINE BIRD.

If we have a combination of words we expect to use together very often, we can create a special understanding token, such as

> Understand "red" or "scarlet" or "vermilion" or "vermillion" or "cinnabar" as "[red]".
> Understand "red/scarlet/vermilion/vermillion/cinnabar" as "[red]".

and then use this to define other understand rules, as in

> Understand "[red] bird" as the robin.

2. Understanding properties and conditional states. Often we want to allow the player to use adjectives or names for objects only at some points in the game or under some circumstances.

> Understand "Janine" as the stranger when the stranger is known.
> Understand the heat property as describing a pan.
> Understand the heat property as referring to a pan.
> Understand "lady" as a woman when the item described is ennobled.

The distinction between referring and describing is that in the "describing" case, the property's name alone can mean the thing in question - so "take unbroken" will work; whereas, in the "referring to", the property's name can only be used as an adjective preceding the name of thing itself - so "take unbroken flowerpot" will work but "take unbroken" will not.

We can also make use of relationships to other things. For instance,

> Understand "[something related by support] taco" as the taco.

allows BEEF TACO to mean the taco when something which can be named BEEF is on top of (that is, supported by) the taco.

If we want to conditionally add to the way the name of something is displayed (e.g., to put "broken" in front of the name of any damaged pot), we may want to use the "printing the name" and "printing the plural name" activities; see the Activities chapter for more details.

3. Understanding actions. We use understand sentences to tell Inform how a player is allowed to give a command.

For clarity, these sample understand rules are listed together with the way the action might be defined:

> Understand "help" as asking for help.
> Asking for help is an action out of world.

> Understand "whistle" as whistling.
> Whistling is an action applying to nothing.

> Understand "shake [something]" as shaking.
> Shaking is an action applying to one thing.

> Understand "seduce [someone]" as seducing.
> Seducing is an action applying to one thing.

> Understand "spy on [any thing]" as spying on.
> Spying on is an action applying to one visible thing.

> Understand "go to [any room]" as going to by name.
> Going to by name is an action applying to one thing.

> Understand "mix [something] with [something]" as mixing it with.
> Mixing it with is an action applying to two things.

> Understand "fill [an open container] with [something]" as inserting it into (with nouns reversed).
> Inserting it into is an action applying to two things.

Notice in this case that, since there are two objects affected by the action, our action name includes an "it" where the first of the two nouns would go.

In a few special cases we might provide an understand rule that accepted unusually terse input:

> Understand "[something]" as examining.
> Understand "[any visited room]" as going to by name.

We may also occasionally write understand rules that supply less information that the action needs to go forward (by offering too few nouns or values), when we intend to use the "supplying a missing noun" or "supplying a missing second noun" activities. So for instance:

> Stabbing it with is an action applying to two things.
> Understand "stab [something] with [something]" as stabbing it with.
> Understand "stab [something]" as stabbing it with.
> Rule for supplying a missing second noun when stabbing something with:
> now the second noun is the hypodermic needle.

For more details, see the Activities chapter.

4. Action synonyms. We may create synonyms for existing commands with lines such as

> Understand the commands "mingle" and "combine" as "mix".

and conversely we may tell Inform not to understand a command in the way it currently does with

> Understand the command "murder" as something new.

Understanding a command as something new removes Inform's knowledge of all grammar applying to that specific word; so

> Understand the command "get" as something new.

would not change Inform's understanding of

> TAKE FISH

but would remove its understanding of

> GET FISH
> GET UP
> GET DOWN
> GET IN BOX
> GET ALL FROM BASKET

and so on. While it might be nice to be able to cancel the understanding of single lines of grammar while leaving all other senses of "get" intact, there is currently no facility for doing this. It is not effective to write a line such as

> Understand the command "get [something]" as something new.

5. Value tokens. Understand rules for actions may also use tokens to accept kinds of value, numbers, or strings of text of any length:

> Understand "discuss [text]" as discussing.
> Discussing is an action applying to one topic.

> Understand "set [something] to [a number]" as dialing it to.
> Dialing it to is an action applying to one thing and one number.

> Understand "sell [something] for [a price]" as selling it for.
> Selling it for is an action applying to one price and one thing.

> Understand "paint [something] [a colour]" as painting it the colour.
> Painting it the colour is an action applying to one thing and one colour.

Subsequently we will be able to refer to the player's chosen input as "the topic understood" (for text), "the number understood", "the colour understood", "the price understood", and so on.

We should bear in mind that, unless we compile to Glulx, Inform will not correctly interpret a number greater than 32767, or units that equate to values larger than this. See the chapter on Units for more discussion of limits on number and unit size.

6. Held objects, multiple objects. Inform provides certain standard tokens to help us define actions that apply to more than one thing, or that imply some particular relationship between the objects named in the command.

> Understand "wave [something preferably held] at [something]" as waving it at.
> Waving it at is an action applying to one carried thing and one visible thing.

The "something preferably held" token tells Inform that, in cases of ambiguity, it should prefer an object which the player already has in inventory to objects that may be visible elsewhere. It is often used in combination with actions applying to carried objects. (For more about carried, visible, and touchable objects, see the Advanced Actions chapter; for more about making the player automatically pick up objects, see the "implicitly taking" activity in the Activities chapter.)

The other special tokens are largely designed to create more reasonable behavior for vague commands involving ALL:

> Understand "repair [things]" as repairing.
> Understand "wave [things preferably held]" as waving.
> Understand "take [things inside] from [something]" as removing it from.
> Understand "put [other things] into/inside/in [something]" as inserting it into.

Here, for instance, we only want TAKE ALL FROM THE SILVER BOX to apply to the items that are already inside the box; and our token will ensure that this happens correctly.

There are also times when we want to make our own, more flexible rules about how Inform should interpret a command from the player that uses the word ALL: for instance, we might want to automatically exclude items of scenery, or prevent the player from accidentally referring to a concealed object. For this purpose, we use not an understand rule but the "deciding whether all includes" activity. See the Activities chapter for more details.

7. Changing what the player is allowed to refer to. If we want a given action to apply to things other than the ordinary set of objects the player can see in front of him, we can use an understand rule to define this. For instance

> Understand "go to [any room]" as distantly approaching.
> Understand "find [any thing]" as seeking.

Understand rules are useful to change what the player may refer to when the change of scope applies to a specific action. They are not so useful for cases where, for instance, the player is in a terrace with a view of a garden, and should be able to refer to attempt any action he likes on any item in the garden, since it's all in view. For that kind of situation, it is better to turn to the "deciding the scope of something" activity, discussed in the Activities chapter.

8. Making guesses about ambiguous commands. If we have given Inform multiple understand rules using the same first word, Inform will sort these rules from most to least specific, and will use the first line matched. Thus if we had

> Understand "push [open door]" as slamming.
> Understand "push [door]" as opening.
> Understand "push [something]" as pushing.

Inform would use the "open door" case if possible, then the "door" case, and finally the "something" case, if the other two did not apply. This can also be used to do some guesswork about what the player intends when a command is ambiguous; if we have both of these lines

> Understand "eat [an edible thing]" as eating.
> Understand "eat [something]" as eating.

Inform will try to look for an edible thing first, and only resort to an inedible object if the player's command cannot refer to anything edible.

Sometimes we will want more specific control over Inform's guesses, or will want to discourage or encourage *all* actions to apply to a particular object:

> Does the player mean taking the great Eiffel Tower: it is very unlikely.
> Does the player mean tying the noun to the noun: it is unlikely.
> Does the player mean doing something to Lord Charisma: it is very likely.

where the outcome may be any of

> it is very likely
> it is likely
> it is possible
> it is unlikely
> it is very unlikely

In the case of multiple interpretations, Inform will accept whichever the rules deem to be likeliest. If there is no clear winner, the player will be asked which item he means.

Finally, there are two activities that affect the way Inform communicates with the player about its guesses, "asking which do you mean" and "clarifying the parser's choice of something". We can use these activities to change the way Inform refers to objects when asking "which do you mean, the X or the Y?" questions, and the way it describes its guesses to the player. See the Activities chapter for more details.

9. Special effects. There are occasionally times when we will want to modify the player's line of input before attempting to understand it; we have seen one or two examples already that use the

> After reading a command: ...

activity in order to achieve special effects. This activity is explained more fully in the activities chapter.

Sometimes it is useful to remove certain punctuation marks from the player's command before interpreting it, so that for instance

> SAY XYZZY TO PRINCE

is treated as identical with

> SAY "XYZZY" TO PRINCE

The Punctuation Removal extension included with Inform provides several phrases to manipulate the player's command to change this sort of thing.

Finally, on occasion we want to be able to record literal text used by the player, for instance when allowing the player to

> RECORD "PASSWORD IS FLAUBERT" IN CASE NOTEBOOK
> WRITE KEITH MARS ON NAMETAG

and so on. Again, Inform does not by default provide resources for handling this kind of need, but there are extensions available (not included in the Inform download) that provide mechanisms to do this more easily.

Previous | Contents | Next