12.19. Changing visibility

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

We first need to remember that darkness affects what actions are even tried, as far as the player's typed commands go. If the player is in a dark room, and there is a screwdriver on the floor, the command EXAMINE SCREWDRIVER will not try any action: the screwdriver is not "in scope", which means that the parser thinks the player does not have any means of knowing it exists. (The rules for scope can be modified - see the chapter on Activities.) But let's suppose that the player types EXAMINE BOOK, and is holding the book in question. The book is now "in scope", so the action "examining the book" is tried.

Some actions require light to be present, and "examining" is one of those. So 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:
> say "You have to squint. Still...";
> there is sufficient light;
> 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).

218
| 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): say "You shine [the lamp] under [the noun]..."; there is sufficient light; there is insufficient light. There is a marble. 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.

Previous | Contents | Next