Inform 7 Home Page / Documentation
§17.9. Understanding kinds of value
In many cases, if K is the name of a kind of value, then Inform automatically makes an Understand token called "[K]" which matches only values of K. An example is "[number]", which matches text like 203 or SEVEN. There is a chart of the kinds of value in the Kinds index for a project, showing which ones can be understood in this way.
In particular, any newly created kind of value can always be understood. We make good use of that in the example story "Studious":
The Studio is a room. "The unreal world of the photographic studio, full of fake furniture, cantilevered stands and silver-white shades like miniature parachutes." The lumpy black camera is in the Studio. "A lumpy black camera hangs from a tripod."
The rake-thin model is a woman in the Studio. "A rake-thin model, exquisitely bored and boringly exquisite, angles herself indolently."
Limb is a kind of value. The limbs are left leg, left arm, right leg and right arm.
Detailing is an action applying to one limb and one visible thing, requiring light. Check detailing: if the camera is not carried then say "You can hardly photograph without a camera, now can you?" instead. Report detailing: say "Click! You take a detail photograph of the [limb understood] of [the second noun]."
Understand "photograph [limb] of [a person]" as detailing.
Test me with "get camera / photograph left leg of model".
Note the way we can refer to the limb mentioned by the player as the "limb understood". Similarly, we could talk about the "number understood" if the value parsed had been a number, and so on.
One of the built-in kinds of value is worth special note: time. A time can hold either a specific time of day, such as 10:23 PM, or a duration of something, such as 21 minutes. The "[a time]" token matches times of day, such as 10:15 AM or MIDNIGHT. But 10 MINUTES wouldn't be recognised by "[a time]" since it isn't a specific moment in the day. To get around this, an alternative version called "[a time period]" is available. So:
Understand "wait for [a time period]" as ...
would match WAIT FOR AN HOUR or WAIT FOR TWO HOURS 12 MINUTES.
|Start of Chapter 17: Understanding|
|Back to §17.8. Understanding names|
|Onward to §17.10. Commands consisting only of nouns|
Suppose we have a book that the player must consult page-by-page, and we want to be able to accept all of the following input:
One approach would be to write many different understand rules and actions: one action for reading randomly, one for reading a specific page, one for reading the first page, one for reading the previous page, one for reading the next page, and one for reading the last page. But this gets tedious to construct and maintain.
More usefully, we could consider that all of the last four options are essentially the same action at heart: the player is asking to read a page in the book using a name rather than a number, and we will have to perform a minor calculation to discover what the number should be. Here's an implementation using named values to resolve this problem:
The Library is a room. The sinister book is carried by the player. The sinister book has a number called the last page read. The sinister book has a number called the length. The length of the sinister book is 50.
Understand "read [number] in/from/of [something]" or "read page [number] in/from/of [something]" or "look up page [number] in/from/of [something]" or "consult page [number] in/from/of [something]" as reading it in. Reading it in is an action applying to one number and one thing, requiring light.
Understand "read [named page] in/from/of [something]" or "read the [named page] in/from/of [something]" as reading it relatively in. Reading it relatively in is an action applying to one named page and one thing, requiring light.
Check reading it in:
if the number understood is greater than the length of the sinister book, say "There are only [length of sinister book in words] pages in the book." instead;
if the number understood is less than 1, say "The page numbering begins with 1." instead.
Carry out reading:
let N be a random number between 1 and the length of the sinister book; now the number understood is N;
say "You flip the pages randomly and arrive at page [the number understood]:[paragraph break]";
try reading the number understood in the sinister book.
"dhuma jyotih salila marutam / samnipatah kva meghah / samdes arthah kva patukaranaih / pranibhih prapaniyah"
"amathesteron pws eipe kai saphesteron"
To read page (N - a number):
now the last page read of the sinister book is N;
if there is a content corresponding to a page of N in the Table of Book Contents:
choose row with a page of N in the Table of Book Contents;
say "You read: '[content entry]'[paragraph break]";
say "Page [N] appears to be blank."
To read page (N - 47):
say "Your eyes burn; your ears ring. Beneath your gaze, the dreadful sigils writhe, reminding you of that which lies outside the edges of the universe...";
end the story saying "You have lost your remaining sanity".
Down in Oodville
Now and then in IF there is a situation where we need to ask the player for a numbered choice rather than an ordinary action command. What's more, that numbered choice might change during the game, so we don't want to just hard-wire the meanings of "1", "2", and "3" whenever the player types them.
A better trick is to keep a list or table (we'll use a table here because it involves slightly less overhead) recording what the player's numerical choices currently mean. Then every time the player selects a number, the table is consulted, and if the number corresponds to something, the player's choice is acted on.
In our example, we'll have a transporter pad that can take the player to any room in the game that he's already visited. (Just for the sake of example, we'll start him off with a few pre-visited rooms.)
Check selecting: [assuming we don't want to be able to transport from just anywhere]
if the player is not on the transporter pad:
say "You can transport only from the transporter pad. From other places than the transporter room, you can HOME to your base ship, but not leap sideways to other locations.";
empty the transport options instead.
if the number understood is greater than the number of filled rows in the Table of Transport Options or the number understood is less than one:
say "[The number understood] is not a valid option. ";
list the transport options instead.
Carry out selecting:
let N be the number understood; [not actually a necessary step, but it makes the next line easier to understand]
choose row N in the Table of Transport Options;
if the transport entry is a room:
move the player to the transport entry;
say "*** BUG: Improperly filled table of transport options ***" [It should not be possible for this to occur, but we add an error message for it so that, if it ever does, we will know what is causing the programming error in our code]
To list the transport options:
let N be 1;
say "From here you could choose to go to: [line break]";
repeat through the Table of Transport Options:
say " [N]: [transport entry][line break]";
To load the transport options:
repeat with interesting room running through visited rooms which are not the Transporter Room:
choose a blank row in the Table of Transport Options;
now the transport entry is the interesting room.
Table of Transport Options
with 3 blank rows. [In the current scenario, the number of blank rows need never be greater than the number of rooms in the game, minus the transport room itself.]
After entering the transporter pad:
say "The transporter beeps and glows amber as you step onto its surface. A moment later a hologram displays your options. [run paragraph on]";
empty the transport options;
load the transport options;
list the transport options.
If we wanted to replace the regular command structure entirely with numbered menus, or use menus to hold conversation options, we could: several Inform extensions provide these functions.
Straw Into Gold
Our example is slightly complicated by the fact that "man" is a name already known to Inform, so we can't re-use it as a kind of value. This is possible to work around, though:
Now we borrow from the Activities chapter to look at the exact wording of the player's command:
After reading a command:
if the player's command includes "[R-name]",
now the R-name of Rumpelstiltskin is the R-name understood;
if the player's command includes "Rumpelstiltskin":
now Rumpelstiltskin is identified;
now Rumpelstiltskin is proper-named.