Inform 7 Home Page / Documentation
§17.11. Understanding values
"Understand" can be used to supply new ways to talk about both things and other values. For instance, if we create:
A brass lantern is in the Building.
then it can be called "brass", or "lantern", but not "lamp": Inform does not really know what these words mean, and has no grasp of synonyms. We can arrange for "lamp" to work as well like so:
Understand "lamp" as the lantern.
Understand "old lamp" as the lantern.
With care, we can do the same trick for entire kinds of thing at once. It is not ordinarily the case that a thing can be called by the name of its kind: if we put a woman called April into a room, then she can usually be called "April", but not "woman". (The exception is when we do not specify any name for her - in that case, Inform will give up and call her just "woman".) So there is not usually any form of words which can refer to anything of a given kind. If we should want this, we have to say so explicitly:
Understand "machine" as a device.
Device is a kind, so now the word "machine" can be used to refer to any device: if there are two in the same place, the result might play out like so:
>switch machine on
Which do you mean, the bale twiner or the grain thresher?
You watch absorbed as a perfect cube of hay is trussed up like a parcel.
Similarly, we might conceivably want to allow new ways to recognise values - in this case, a number:
Understand "eleventy-one" as 111.
When making complicated names, we need to watch out for the possibility of writing a definition which will cause Inform to go around in circles (something which will show up as a "Too many activities at once" run-time problem). For instance,
Understand "[thing] substitute" as the placebo.
will fail because Inform, working left to right, needs to look for every possible object name before it can progress: one possibility is the placebo itself: to check that, it needs to look for every possible object name: and so on, never finishing. A definition like this one very likely matches too much in any case (would we really want to accept PLACEBO SUBSTITUTE or CIGARETTE SUBSTITUTE SUBSTITUTE SUBSTITUTE here, as the definition implies?).
|Start of Chapter 17: Understanding|
|Back to §17.10. Commands consisting only of nouns|
|Onward to §17.12. This/that|
There are hundreds of traditional pigments, from lampblack to burnt sienna, so we will confine ourselves to just two:
Painting is an action applying to one thing and one colour. Check painting: if the noun is not the canvas, say "Centuries of tradition suggest that canvas is the natural home of paint." instead. Carry out painting: now the colour of the canvas is the colour understood. Report painting: say "You splash away at the now [canvas]."
The "reading a command" activity is rather advanced; for the moment, what we need to understand is that we're intervening in commands at the start of play and insisting that the player's first instruction to the game consist of a choice of gender. After that point, the gender will be set and play will proceed as normal.
In order to do the parsing, we define gender as a kind of value, and give several alternate names to each gender.
After reading a command when the gender of the player is unknown:
if the player's command includes "[gender]":
now the gender of the player is the gender understood;
if the gender of the player is unknown:
say "This story requires a selection of male or female. [run paragraph on]";
reject the player's command;
if the gender of the player is masculine, now the player is male;
if the gender of the player is feminine, now the player is female;
say "[line break]Thank you. We now begin...";
now the command prompt is ">";
move the player to Sandy Beach;
reject the player's command;
say "Sorry, we're not ready to go on yet. [run paragraph on]";
reject the player's command.
If we had a whole series of things to ask the player about, we might define a whole series of kinds of value
and use a "construction stage" variable to keep track of the current stage of character-construction, as in