Inform 7 Home Page / Documentation
§17.17. Context: understanding when
We have now seen several different forms of "Understand" sentence: for instance,
Understand the colour property as describing a building block.
Understand "mix [colour] paint" as mixing paint.
Understand "rouge" as red.
Understand "curious girl" as Alice.
Any of these may optionally have a condition tacked on: for instance,
Understand "mix [colour] paint" as mixing paint when the location is the Workshop.
Understand "rouge" as red when the make-up set is visible.
In principle, "when ..." can take in any condition at all. In practice a little care should be exercised not to do anything too slow, or which might have side-effects. (For instance, referring the decision to a phrase which then printed text up would be a bad idea.) Moreover, we must remember that the "noun" and "second noun" are not known yet, nor do we know what the action will be. So we cannot safely say "when the noun is the fir cone", for instance, or refer to things like "the number understood". (We aren't done understanding yet.) If we want more sophisticated handling of such cases, we need to write checking rules and so on in the usual way.
Contexts can be useful to make sense of things having different names depending on who is being spoken to, as here:
Understand "your" as a thing when the item described is held by the person asked.
With this rule in place FRODO, GIVE ME YOUR RING means that Frodo will know which ring is meant, even if there are a couple of dozen other rings present.
If the name of something has to change completely, perhaps because the player's understanding of events has changed completely, then Inform's standard way of handling names can be a nuisance. When an item or room is created, Inform automatically makes its name understood as referring to it (in fact, it makes each individual word in that name understood). For instance,
The Wabe is a room. The blue peacock and the sundial are in the Wabe.
means that the player can type EXAMINE BLUE PEACOCK or PUSH SUNDIAL or SHOWME WABE or TAKE BLUE, and so on. This is almost always a good thing, and here there's no problem, because peacocks and sundials are not usually disguised. But here is a case where a disguise is needed:
The secret document is a privately-named thing in the drawer.
The printed name of the secret document is "[if the secret document is handled]secret document[otherwise]dusty paper".
Understand "dusty" and "paper" as the secret document.
Understand "secret" and "document" as the secret document when the secret document is handled.
After taking the secret document for the first time: say "Heavens! It is the secret document!"
As this demonstrates, the either/or property "privately-named" makes Inform create a thing or room which starts out with no automatic understandings at all. The name it happens to have in the source text is ignored. If we simply write:
The ungraspable concept is a privately-named thing in the Dining Room.
then nothing the player can type will ever refer to it; though he will see it, and even be able to pick it up by typing TAKE ALL.
The reverse property is "publicly-named", which all things and rooms are by default.
Inform has four built-in kinds of object (room, thing, direction and region), and all of those have this either/or property. When we create new kinds, they're normally kinds of those four fundamental ones, so they pick up the same behaviour. But if we create a new kind of object outside of these four, that won't be true unless we make it so:
A concept is a kind of object. A concept can be privately-named or publicly-named. A concept is usually publicly-named.
(Privately-named is a property which only affects how Inform creates the object, and it can't usefully be given or taken away during play. "Understand ... when ..." is the way to change names during play.)
|
ExampleQuiz Show
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.
|
|
"Quiz Show" by Mike Tarbert
Use scoring.
Answer mode is a truth state that varies.
Current state is a text that varies.
Guessing is an action applying to one topic.
Understand "[text]" as guessing when answer mode is true.
Because of the "...when" part of this line, random text is only treated as an answer when a question is being asked.
Check guessing (this is the default wrong answer rule):
if the topic understood is not a topic listed in the Table of Dates of Statehood:
say "Wrong!";
now answer mode is false.
Carry out guessing a topic listed in the Table of Dates of Statehood:
if state entry is the current state:
say "Correct! ([comment entry], to be exact!)";
increase the score by one;
otherwise:
say "Wrong!";
now answer mode is false.
This next rule allows a player to do something other than answer the question, but then makes him wait for another question before answering.
Before doing anything other than guessing:
if answer mode is true:
say "(ignoring the question)[line break]";
now answer mode is false.
Section 2 - Scenario
The Lab is a room. Sam is a man in the lab.
Every turn when the player is in the lab:
if a random chance of 3 in 5 succeeds:
choose a random row in the Table of Dates of Statehood;
say "Sam asks you, 'In what year was [state entry] admitted into the Union?'";
now current state is state entry;
now answer mode is true.
Table of Dates of Statehood
State
|
Topic
|
Comment
|
"Florida"
|
"1845"
|
"March 3rd"
|
"Delaware"
|
"1787"
|
"December 7th"
|
"Hawaii"
|
"1960"
|
"July 4th"
|
Test me with "1845 / z / z / 1787 / 1792 / z / 1845 / g".
Note that the situation will become a little more complicated if we have two or more identical topics in our trivia list; in that case, we would need to loop through the Table of Dates of Statehood explicitly, and only mark the player wrong if none of the lines were found to match. (See the chapter on Tables for many more ways to manipulate table behavior.)
|
ExampleBibliophilia
A bookshelf with a number of books, where the player's command to examine something will be interpreted as an attempt to look up titles if the bookshelf is present, but otherwise given the usual response.
|
|
Suppose we want a bookshelf with a very large number of books on it. They aren't to be taken or carried around in the game, but they should be mentioned, and the player should be allowed to look them up by name. Furthermore, the player's attempts to examine something unrecognized should be understood as an attempt to look up a title -- but only when the player is in the presence of the books. The rest of the time such requests should be rejected in the usual way.
"Bibliophilia"
The Graduate Lounge is a room. "Shabby sofas; plastic cups remaining from the afternoon's pre-lecture espresso; a collection of Xena and Hercules figurines posed for ironic effect. It's somewhat depressing at this hour, when everyone has gone home."
The Classics Reading Room is south of the Lounge. "Not as large a collection as the one in the Library, but it contains copies of everything really essential for reference."
Understand "examine [text]" as examining as a book when the player is in the Reading Room. Understand "look up [text]" as examining as a book when the player is in the Reading Room.
Examining as a book is an action applying to one topic.
Carry out examining as a book:
say "You can't find any such text."
Instead of examining as a book a topic listed in the Table of Book Titles:
say "[description entry][paragraph break]"
Table of Book Titles
topic
|
title
|
description
|
"Reading Greek Death" or "reading/greek/death" or "greek death"
|
"Reading Greek Death"
|
"A dense orange paperback treatise on the development of Greek eschatology."
|
"TAPA/Transactions/134-2"
|
"TAPA 134-2"
|
"Transactions of the American Philological Association from 2004."
|
"Oxford Classical Dictionary" or "OCD/dictionary/classical/oxford"
|
"Oxford Classical Dictionary"
|
"A hefty reference with short articles on everything from Greek meter to ancient cosmetics."
|
"Collected Dialogues of Plato" or "Plato/dialogues/hamilton/cairns"
|
"Collected Dialogues of Plato"
|
"All the Platonic dialogues -- some, admittedly, in rather tired translations -- but still a useful single volume, ed. Edith Hamilton and Huntington Cairns."
|
"Adobe Illustrator CS User Guide" or "user guide" or "adobe illustrator" or "adobe/illustrator/cs/user/guide"
|
"Adobe Illustrator CS User Guide"
|
"Hello, how did this get here? A suspiciously familiar name is scribbled inside the front cover..."
|
Some books are scenery in the Reading Room. Understand "copies" or "book" or "shelf" or "shelves" as the books. Instead of examining the books:
choose a random row in the Table of Book Titles;
say "You scan the shelves and notice, among others, a volume entitled [italic type][title entry][roman type]."
Test me with "south / examine ocd / examine books / examine books / examine plato / n / x hercules / s / x hercules".
Now if we type >X HERCULES in the Lounge, we will get
>x hercules
You can't see any such thing.
thanks to our somewhat slovenly implementation of the Lounge scenery; but in the Reading Room,
>x hercules
You can't find any such text.
In practice we might also want to extend our coverage somewhat to handle a case where the player tried to take books from the bookshelf: currently that would not be understood.