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:
"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".
We rely here on the understanding-by-relations rules we've already learned, but there is an additional trick: we want to make sure that if the player types "original" or "actual", this word will not be taken to refer to the thing modeled:
"Originals"
A model is a kind of thing. 10 models are in the model-repository.
Appearance relates one thing to various models. The verb to be shown by means the appearance relation.
Indication relates a model (called X) to a thing (called Y) when Y is shown by X and Y is suitable.
Understand "actual" or "original" as "[actual]". Understand "[actual]" as something when the item described is not a model.
Definition: a thing is suitable:
if the player's command includes "[actual]", no;
yes.
Understand "[something related by indication]" as a model.
After printing the name of a model (called target): say " [random thing shown by the target]"
Now our duplication command -- for the sake of simplicity, we'll suppose that in this scenario the player is duplicating objects by magic rather than creating them out of physical materials or supplies:
Understand "duplicate [something]" as duplicating. Duplicating is an action applying to one visible thing.
The duplicating action has an object called the selected model.
Setting action variables for duplicating:
let N be a random model in the model-repository;
now the selected model is N.
Check duplicating:
if the selected model is nothing, say "You're out of power." instead.
Carry out duplicating:
now the noun is shown by the selected model;
move the selected model to the player.
Report duplicating:
say "You concentrate and manifest [a selected model]."
Now, the challenge is that we want to print the word "actual" before printing the name of an object, but only during disambiguation questions and only when we are not printing the name of the object as part of a model-name! (If we are not careful about the latter point, we will get responses such as "Which do you mean, the model actual deer or the actual deer?" which of course defeats the whole purpose.
The way around this is to remember that activities stack: we're printing the name of the deer while printing the name of a model that involves the deer. So if we set a flag while printing the name of a model, we can control the way the deer's name prints during the transaction. (We could use our ...while clause to specify while not printing the name of a model, except that we're already using it for "while asking which do you mean", and these do not stack.) So:
The virtual-context is a truth state that varies. The virtual-context is false.
Before printing the name of a model:
now virtual-context is true.
After printing the name of a model:
now virtual-context is false.
Before printing the name of something (called target) while asking which do you mean:
if the target is not a model and virtual-context is false:
say "actual ".
Forest is a room. It contains a deer and a daisy. The deer is an animal.
Test me with "duplicate deer / x model deer / x deer model / drop deer / x deer / actual / x deer / model".
Suppose we want our game to respond 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?"
For the case of EXAMINE WALL, we need a way to determine whether every item being disambiguated is a direction. We'll start by making a "matched" adjective which will identify items being disambiguated:
"Walls and Noses"
Eight-Walled Chamber is a room. "A perfectly octagonal room whose walls are tinted in various hues."
Understand "wall" as a direction.
Definition: a direction is matched if it fits the parse list.
Definition: a room is matched if it fits the parse list.
Definition: a thing is matched if it fits the parse list.
Rule for asking which do you mean when everything matched is direction:
say "In which direction?"
Checking the parse list requires a bit of behind-the-scenes work with Inform 6. Fortunately, you don't have to understand this entirely in order to use the rest of the example:
To decide whether (N - an object) fits the parse list:
(- (FindInParseList({N})) -)
Include (-
[ FindInParseList obj i k marker;
marker = 0;
for (i=1 : i<=number_of_classes : i++) {
while (((match_classes-->marker) ~= i) && ((match_classes-->marker) ~= -i)) marker++;
k = match_list-->marker;
if (k==obj) rtrue;
}
rfalse;
];
-)
Now that we've defined our "matched" adjective, we can use it for other purposes as well -- even generating our own lists. Our second challenge was to respond to EXAMINE NOSE with "Whose nose do you mean, Frederica's, Betty's, Wilma's or your own?"
Here we need to change the way the question is worded (not "which do you mean" but "whose nose do you mean"). We also have to the names of the noses as they're printed in this particular context, so that they don't repeat the word "nose" over and over. And -- as a point of good English style -- we also want "your own" nose always to be last on the list.
For this purpose we may want to use the built-in "Complex Listing" extension, which allows us to print specially ordered lists. So:
Include Complex Listing by Emily Short.
Wilma, Betty, and Frederica are women in the Eight-Walled Chamber. Understand "lady" or "woman" as a woman. A nose is a kind of thing. A nose is part of every person.
Rule for asking which do you mean when everything matched is a nose:
prepare a list of matched things;
if your nose is an output listed in the Table of Scored Listing:
choose row with an output of your nose in the Table of Scored Listing;
now the assigned score entry is -1;
say "Whose nose do you mean, [the prepared list delimited in disjunctive style]?"
Rule for printing the name of a nose (called target) while asking which do you mean :
if everything matched is a nose:
if the target is part of a person (called owner):
if the owner is the player, say "your own";
otherwise say "[the owner][apostrophe]s";
otherwise:
make no decision.
Understand "own" or "mine" as your nose.
Test me with "x wall / north / x nose / mine".