§6.17. Clarification and Correction

Some commands and some objects raise special challenges when it comes to working out the player's intention.

Sometimes this can be done with good rules about the assumptions Inform should make. Alpaca Farm demonstrates a USE command, always a challenge because USE can mean very different actions with different items.

There are also times when we need to ask the player for more information. Apples demonstrates how sensibly to use properties to disambiguate between similar objects, while Walls and Noses rephrases the disambiguation question when special objects are involved: examining one of the walls of the room will make the game ask "In which direction?" and EXAMINE NOSE will lead to "Whose nose do you mean, Frederica's, Betty's, Wilma's or your own?"

At other times, the player types something that is wrong in a predictable way: for instance, we might want to remove all the "with..." phrases from commands like

HIT DOOR WITH FIST
KICK DRAGON WITH FOOT
LOOK WEST WITH EYES

and merely parse the remainder of the command. (That last command may be unlikely, but novice players do quite often type commands that refer unnecessarily to body parts.) Cave-troll demonstrates how.

WXPQ demonstrates how to modify the error message the parser gives in response to a command it doesn't understand; this particular example focuses on the "That noun doesn't make sense in this context" message that arises from using the "[any thing]" or "[any room]" tokens, but the techniques could be adapted to handling other parser errors as well.

For catching typing errors, Cedric Knight's extension Mistype may also be of use: it provides an automatic typo-correction function that the player can turn on or off.


arrow-up.pngStart of Chapter 6: Commands
arrow-left.pngBack to §6.16. Alternate Default Messages
arrow-right.pngOnward to §6.18. Alternatives To Standard Parsing

*ExampleAlpaca Farm
A generic USE action which behaves sensibly with a range of different objects.

Inform by default detects whether two objects can be disambiguated by any vocabulary available to the player. If so, it asks a question; if not, it picks one of the identical objects at random.

Generally this produces good behavior. Occasionally, though, two objects have some distinguishing characteristic that doesn't appear in the object name. For instance, suppose we've created a class of apples that can be told apart depending on whether they've been bitten or not:

An apple is a kind of thing. Consumption is a kind of value. The consumptions are pristine and bitten. An apple has a consumption. The description of an apple is "It is [consumption]."

Understand the consumption property as describing an apple.

The player can meaningfully type

>EAT BITTEN APPLE

or

>EAT PRISTINE APPLE

but if he types

>EAT APPLE

Inform will, annoyingly, ask

Which do you mean, an apple or the apple?

This gives the player no indication of why Inform is making a distinction. So here we add a special "printing the name" rule to get around that situation:

paste.png "Apples"

Orchard is a room.

An apple is a kind of thing. Consumption is a kind of value. The consumptions are pristine and bitten. An apple has a consumption. The description of an apple is "It is [consumption]."

Understand the consumption property as describing an apple.

Before printing the name of an apple while asking which do you mean: say "[consumption] ". Before printing the plural name of an apple while asking which do you mean: say "[consumption] ".

The player carries three apples.

Instead of eating a pristine apple (called the fruit):
    say "You take a satisfying bite.";
    now the fruit is bitten.

Instead of eating a bitten apple (called the fruit):
    say "You consume the apple entirely.";
    now the fruit is nowhere.

Inform will also separate the bitten from the pristine apples in inventory listings and room descriptions, even though it's not clear why; we can improve on that behavior thus:

Before listing contents: group apples together.

Rule for grouping together an apple (called target):
    let source be the holder of the target;
    say "[number of apples held by the source in words] apple[s], some bitten".

Before printing the plural name of an apple (called target):
    let source be the holder of the target;
    if every apple held by the source is bitten, say "bitten ";
    if every apple held by the source is pristine, say "pristine ".

Test me with "i / eat apple / i / eat apple / pristine / i / eat apple / pristine / i".

*ExampleApples
Prompting the player on how to disambiguate otherwise similar objects.

Inform by default detects whether two objects can be disambiguated by any vocabulary available to the player. If so, it asks a question; if not, it picks one of the identical objects at random.

Generally this produces good behavior. Occasionally, though, two objects have some distinguishing characteristic that doesn't appear in the object name. For instance, suppose we've created a class of apples that can be told apart depending on whether they've been bitten or not:

An apple is a kind of thing. Consumption is a kind of value. The consumptions are pristine and bitten. An apple has a consumption. The description of an apple is "It is [consumption]."

Understand the consumption property as describing an apple.

The player can meaningfully type

>EAT BITTEN APPLE

or

>EAT PRISTINE APPLE

but if he types

>EAT APPLE

Inform will, annoyingly, ask

Which do you mean, an apple or the apple?

This gives the player no indication of why Inform is making a distinction. So here we add a special "printing the name" rule to get around that situation:

paste.png "Apples"

Orchard is a room.

An apple is a kind of thing. Consumption is a kind of value. The consumptions are pristine and bitten. An apple has a consumption. The description of an apple is "It is [consumption]."

Understand the consumption property as describing an apple.

Before printing the name of an apple while asking which do you mean: say "[consumption] ". Before printing the plural name of an apple while asking which do you mean: say "[consumption] ".

The player carries three apples.

Instead of eating a pristine apple (called the fruit):
    say "You take a satisfying bite.";
    now the fruit is bitten.

Instead of eating a bitten apple (called the fruit):
    say "You consume the apple entirely.";
    now the fruit is nowhere.

Inform will also separate the bitten from the pristine apples in inventory listings and room descriptions, even though it's not clear why; we can improve on that behavior thus:

Before listing contents: group apples together.

Rule for grouping together an apple (called target):
    let source be the holder of the target;
    say "[number of apples held by the source in words] apple[s], some bitten".

Before printing the plural name of an apple (called target):
    let source be the holder of the target;
    if every apple held by the source is bitten, say "bitten ";
    if every apple held by the source is pristine, say "pristine ".

Test me with "i / eat apple / i / eat apple / pristine / i / eat apple / pristine / i".

*ExampleWXPQ
Creating a more sensible parser error than "that noun did not make sense in this context".

***ExampleWalls and Noses
Responding to "EXAMINE WALL" with "In which direction?", and to "EXAMINE NOSE" with "Whose nose do you mean, Frederica's, Betty's, Wilma's or your own?"

***ExampleCave-troll
Determining that the command the player typed is invalid, editing it, and re-examining it to see whether it now reads correctly.