Chapter 16: Understanding
16.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 game "Studious":

"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.


292
* Example  Pages
A book with pages that can be read by number (as in "read page 3 in...") and which accepts relative page references as well (such as "read the last page of...", "read the next page", and so on).

RB
293
** Example  Down in Oodville
Offering the player a choice of numbered options at certain times, without otherwise interfering with his ability to give regular commands.

RB

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.)

"Down in Oodville"

Section 1 - Method

Understand "[number]" as selecting.

Selecting is an action applying to one number.

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.

Check selecting:
    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;
    otherwise:
        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]";
        increment N.

To empty the transport options:
    repeat through the Table of Transport Options:
        blank out the whole row; [first we empty the table]

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
transport
an object
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.]

Understand "home" as homing. Homing is an action applying to nothing.

Check homing:
    if the player is in the Transporter Room:
        say "You're already here!" instead.

Carry out homing:
    move the player to the transporter room.

Section 2 - Scenario

The Transporter Room is a room.

Oodville is a visited room.

Midnight is a visited room. The Diamond City is west of Midnight.

The transporter pad is an enterable supporter in the Transporter Room. "The transporter pad in the middle of the floor is currently dull blue: powered but unoccupied."

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.

Test me with "get on pad / 0 / -1 / 8 / 2 / look / w / home / get on pad / get off pad / 3".

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.

294
*** Example  Straw Into Gold
Creating a Rumpelstiltskin character who is always referred to as "dwarf", "guy", "dude", or "man" -- depending on which the player last used -- until the first time the player refers to him as "Rumpelstiltskin".

RB


PreviousContentsNext