Chapter 12: Advanced Actions
12.19. Changing visibility

Ordinarily, Inform has a simple model for visibility: it is either fully light or it is fully dark, and certain actions are impossible in the dark, such as examining something. If an action is tried which was defined as requiring light, Inform consults the visibility rules to see if it can go ahead. By default, there is only one visibility rule, which says "yes" in the light and "no" in darkness. Here, though, we create another one:

Visibility rule when in darkness:
    if examining the book begin;
        say "You have to squint. Still...";
        there is sufficient light;
    end if;
    there is insufficient light.

A visibility rule must always conclude "there is sufficient light", or "there is insufficient light", or else do nothing and leave it to other rules to decide.

It is a possibly unexpected fact that "looking" does not require light, but instead behaves differently in darkness - it prints a pseudo-room-description such as

Darkness
It is pitch dark, and you can't see a thing.

instead of printing the description of the player's current room. This means that the "looking" action is unaffected by visibility rules. All the same, what "looking" does in the dark can be changed by using the two activities "printing the name of a dark room" and "printing the description of a dark room" (see the Activities chapter for details).


201
* Example  Flashlight
Visibility set so that looking under objects produces no result unless the player has a light source to shine there (regardless of the light level of the room).

RB

"Flashlight"

The Schoolhouse is a room. "Though normally comfortable, the room is dark and menacing during the storm; rain sheets on the windows, and you can barely see the flash of the lighthouse only a few miles away."

The cabinet is a fixed in place openable container in the Schoolhouse. The hurricane lantern is a thing in the Schoolhouse. "A hurricane lantern hangs from a peg." The lantern is lit.

Visibility rule when looking under something:
    if the player is carrying a lit thing (called lamp)
    begin;
        say "You shine [the lamp] under [the noun]...";
        there is sufficient light;
    end if;
    there is insufficient light.

The marble is a thing. The marble can be found or lost. The marble is lost.

Instead of looking under the cabinet when the marble is lost:
    move the marble to the player;
    now the marble is found;
    say "Billy's lost marble! So that's where it got to!"

Test me with "look under cabinet / get lantern / look under cabinet".

Because visibility is checked before instead rules, this discovery will (correctly) occur only when the player does have enough light.


PreviousContentsNext