Inform 7 Home Page / Documentation
§3.5. Doors, Staircases, and Bridges
Inform's "door" kind provides for a tangible thing which comes between one room and another. A door can be open or closed, and openable or not: it can be locked or unlocked, and lockable or not. Here we create a conventional door, a natural gap in the rocks, and a (fixed in place) wooden ladder:
The fire door is an open door. The fire door is east of the Projection Booth and west of the Fire Escape.
The narrow crevice is an open unopenable door. The crevice is east of the Col du Prafleuri and west of Rocky Knoll Above Arolla.
The wooden ladder is an open unopenable door. The ladder is above the Stableyard and below the Hay Loft.
Most doors are visible from both sides: they are single objects but present in two rooms at once, which raises a number of complications. Inform normally uses the same description looking from each way, which is not very interesting: When? and Whence? demonstrate neat ways to describe the two sides differently, and Whither? adds the option for the player to refer to doors as "the west door" and "the east door" automatically.
Neighbourhood Watch goes further by making a door behave differently on each side: from the "outside" you need a key, but "inside" it opens on a latch. Finally, Garibaldi 1 shows how to access information about the two sides of a door.
Higher Calling demonstrates doors which automatically open as needed: though using the Inform extension Locksmith by Emily Short is probably easier and better. Elsie, conversely, demonstrates a door that closes one turn after the player has opened it.
Certain complications apply when characters other than the player have to see and interact with doors that exist in other rooms. Wainwright Acts demonstrates the syntax needed to handle this technically quirky situation.
Something Narsty and Hayseed provide a "staircase" kind useful for vertically arranged, always-open doors like staircases and (fixed in place) ladders.
One Short Plank implements a precarious plank bridge across a chasm as an open unopenable door.
See Windows for climbing through a window from one room to another
See Ropes for portable connections between rooms, much of the development of which could be adapted to handle portable ladders. "Doors" are never allowed to move
See Magic (Breaking the Laws of Physics) for a hat that lets the player walk through closed doors
See Modifying Existing Commands for ways to allow the player to unlock with a key he isn't currently holding
In a game with many staircases, we might want:
Defining the staircase this way means that we will never be able to get away with (for instance) a folding ladder into the attic which is sometimes closed up. So alternatively we might do
We could then write a rule so that whenever the player types CLIMB [any staircase], the command is diverted to an enter command, while all other doors refuse to respond to such treatment. Still, this kind is now usable, as we see in this trivial example:
But these are refinements for a later chapter.
Very simple, but quite frequently useful:
Presumably all staircase-type connections between rooms should respond when the player says CLIMB STAIRS (or the equivalent). So
Attempts to climb other types of door will still be treated as useless.
"Called" is quite useful in the context of rules about going, since go rules often refer to things other than the noun the player typed. For instance, suppose we want to have doors which politely open when the player tries to pass through them:
Before going through a closed door (called the blocking door):
say "(first opening [the blocking door])[line break]";
silently try opening the blocking door;
if the blocking door is closed, stop the action.
Dome is a room. North of Dome is North Chapel. South of the Dome is South Chapel. West of the Dome is Western End. Quiet Corner is northwest of the Dome, north of Western End, and west of North Chapel. Loud Corner is east of North Chapel, northeast of Dome, and north of Eastern End. Eastern End is north of Dim Corner and east of Dome. Dim Corner is southeast of Dome and east of South Chapel. Ruined Corner is southwest of Dome, west of South Chapel, and south of Western End.
A fuller set of such rules is included in the Locksmith extension.
Suppose we wanted to write rules for a character who will interact with doors in other locations even when the player is not present. This poses a little challenge: doors are actually single objects, and -- with the same shuffling of stage properties that applies to backdrops -- they are moved as needed to represent the door object in whatever room contains the player.
That means that it isn't safe to rely on a phrase like
because, even if Bernard's location is connected by doors to other places, the actual representation of that door may not be "in" Bernard's location, from the model's point of view, at this exact moment.
This does not, of course, mean that we can't ask this question; just that we have to be a little cleverer about how we phrase it. Every door has properties that correspond to the two locations
We can make this information easier to check with a conditional relation, like so:
And this allows us to write rules that have characters interacting with doors even in the player's absence:
The Waiting Room is a room. The waiting room door is west of the Waiting Room and east of the Gents' Loo. The Waiting Room door is an open door. "The waiting room door [if open]stands open[otherwise]is shut firmly[end if]."
repeat with indiscreet one running through other people:
repeat with port running through open doors that are a threshold of the location of the indiscreet one:
if the port is a threshold of the location and the indiscreet one is not in the location:
say "Through [the port], you overhear [the indiscreet one] discussing [one of]his hopes for your imminent resignation[or]your wife's infidelity[or]your financially straitened circumstances[or]ways to avoid attending your birthday party[or]your halitosis[as decreasingly likely outcomes]."
Here we expand on the simple examples When? and Whence?; this time we want the player to be able to refer to doors by their directions, as in "the west door" when the door in question does in fact lead west.
The initial appearance of a door is usually "Nearby [an item described] leads [if the other side of the item described is visited][direction of the item described from the location] to [other side of the item described][otherwise][direction of the item described from the location][end if]."
Direction-relevance relates a door (called X) to a direction (called Y) when the direction of X from the location is Y. The verb to be directionally-relevant to means the direction-relevance relation.
As an added touch, we respond also to the case where the player postulates a door in some direction when there is no such thing at the moment:
Suppose we want a locked door that can be opened with a key, but is also openable by hand without a key from one side only. We start by defining an ordinary lockable door and the key that controls it:
The next part is going to require that we modify the normal operation of the "lock" command. "Lock" ordinarily requires that the player supply two objects: a thing he wants to unlock, and the key he wants to use on it. The full command is LOCK DOOR WITH THE KEY, and Inform will not accept simply LOCK DOOR as locking.
Therefore, we're going to need to create our own new variant on the lock verb (and the unlock verb, while we're at it). The full procedure for this is laid out in the chapters on Action and Understanding, but here is an example:
Here we've created a new action -- locking something without a key -- and we've told Inform to understand LOCK DOOR as this action, rather than an incomplete command to LOCK DOOR WITH SOMETHING.
Now we add some instructions so that the game will not let us use this keyless unlocking command unless we're in the right place or are properly equipped:
Check locking keylessly:
if the noun is not a door, say "[The noun] is not something you can lock." instead;
if the noun is locked, say "[The noun] is already locked." instead;
if the player carries the brass key and the player is in the Stairwell, try locking the noun with the brass key instead;
if the player is in the Stairwell, say "You can't lock the door from this side without the key." instead.
This check rule is performed before the keyless locking action succeeds. The first thing we do is try to use the key if the player is outside and has the key: this way, LOCK DOOR will turn automatically into LOCK DOOR WITH THE KEY, under circumstances where that is both possible and necessary.
The second thing is to check whether the player is outside but keyless, and, if so stop the action from being performed successfully. Here we print a failure message followed by the word "instead", which tells Inform that we've substituted some other outcome for the usual performance of the action.
Now we're reasonably sure that the player is only locking keylessly in the case that he is inside the Studio. (We might have to do a more thorough check for this if there were more than two rooms, but as it is, the player can only be in the Stairwell or in the Studio, so if we have ruled out the Stairwell, we are safe.) So now we want to add what happens when locking-without-a-key command succeeds:
That's it. We've just told Inform to make the door be locked. "Now..." syntax will be explained more thoroughly in the chapter on change. But we still haven't described to the player what just happened, so let's provide a description of that, too:
And now we have to do a similar set of things for unlocking:
Check unlocking keylessly:
if the noun is not a door, say "[The noun] is not something you can lock." instead;
if the noun is unlocked, say "[The noun] is already unlocked." instead;
if the player carries the brass key and the player is in the Stairwell, try unlocking the noun with the brass key instead;
if the player is in the Stairwell, say "You can't unlock the door from this side without the key." instead.
Some (but not all) of this work is done for you if you like by the Locksmith extension. If you prefer, you can include that extension, then follow the documentation in order to implement the remainder of the scenario. Locksmith takes care of implementing the additional locking and unlocking actions, and provides some other conveniences.
One Short Plank
The East Jungle is a room. The plank bridge is west of the East Jungle and east of the West Jungle. The plank is an open unopenable door. "A precarious plank bridge extends [if the location is West Jungle]east[otherwise]west[end if] across the chasm." The description of the plank is "Extremely fragile and precarious."
Instead of going through the plank when the player is carrying something:
say "You step gingerly across the plank, which bows under your weight. But your meagre possessions are the straw which breaks the camel's back!";
end the story.
But indeed, why stop there?
Suppose we want to create an automated door of the sort that closes when it isn't in use. A convenient way is to write a rule that fires "every turn when the sliding door was open". This will be true only if the door was open at the beginning of the turn: if the player just opened it this turn, it stays open, and if it was already closed, it stays closed. Thus:
The axis-ward is a direction. The opposite of axis-ward is hub-ward. Understand "aw" or "axisward" as axis-ward.
The hub-ward is a direction. The opposite of hub-ward is axis-ward. Understand "hw" or "hubward" as hub-ward.
The sliding door is a door. It is axis-ward from Bridge and hub-ward from C Deck. The initial appearance is "There is a door in this wall[if closed] -- or at least, the potential for a door, since currently it is sealed, distinguishable from the rest of the wall only by the warning stripes on its surface[end if]."
Every turn when the sliding door was open:
now the sliding door is closed;
if the player can see the sliding door:
say "The sliding door slips back into place, sealing the wall as though there had never been a breach."
Suppose we would like to allow the player to view the status of all the doors functioning in the game; and we want to identify those doors by mentioning which two rooms they connect. The following uses some techniques that will be covered in later chapters, but the basic idea may be obvious:
Instead of examining the switched on security readout:
say "The screen reads: [fixed letter spacing]";
say line break;
repeat with item running through doors:
say line break;
say " [item] ([front side of the item]/[back side of the item]): [if the item is locked]LOCKED[otherwise]UNLOCKED[end if]";
say variable letter spacing;
say paragraph break.
It is more or less arbitrary which room winds up as the "front side" and which as the "back", but in this case it hardly matters.
The Docking Bay is a room. The inner airlock is a door. It is north of the Docking Bay and south of the Zocalo. The inner airlock is lockable and unlocked. The outer airlock is lockable and locked. It is a door. It is south of the Docking Bay and north of Space.
It would be fairly tedious reading to have a large game full of doors that describe themselves this way. Nonetheless, if we insisted we could use our knowledge of the map as leverage to make every door in the game describe itself automatically.
To do this, we make use of the phrase "direction of (the door) from (a room)" -- in this case, the direction of the door we're looking at when viewed from the player's location. Thus:
The initial appearance of a door is usually "Nearby [an item described] leads [if the other side of the item described is visited][direction of the item described from the location] to [the other side of the item described][otherwise][direction of the item described from the location][end if]."
Yet a further variation on this, which can automatically understand "the east door" and "the west door" when appropriate, may be found in the example "Whither?".