1
<HTML><HEAD><TITLE>Section 12: Doors</TITLE></HEAD>
2
<BODY BGCOLOR="#FFFFFF">
5
<TR><TD Valign="top"><A HREF="contents.html">Contents</A><BR><A HREF="section11.html">Back</A><BR><A HREF="section13.html">Forward</A><TD bgcolor="#F5DEB3"><BLOCKQUOTE><H3>12. Doors</H3></BLOCKQUOTE><TR><TD><TD>
9
Standing in front of you to the north, however, is a door surpassing
10
anything you could have imagined. For starters, its massive lock is
11
wrapped in a dozen six-inch thick iron chains. In addition, a certain
12
five-headed monster...
13
<P>...Marc Blank and P. David Lebling, <I>'Enchanter'</I></BLOCKQUOTE>
15
<BR>O for doors to be open and an invite with gilded edges
16
<BR>To dine with Lord Lobcock and Count Asthma.
17
<BR><P>...W. H. Auden (<B>1907</B>--<B>1973</B>), <I>Song</I></BLOCKQUOTE>
21
A useful kind of object is a <TT>door</TT>. This need not literally be a door:
22
it might be a rope-bridge or a ladder, for instance. To set up a <TT>door</TT>:
24
<P>(a) -- give the object the <TT>door</TT> attribute;
25
<P>(b) -- set its <TT>door_to</TT> property to the destination;
26
<P>(c) -- set its <TT>door_dir</TT> property to the direction which that would be,
27
such as <TT>n_to</TT>;
28
<P>(d) -- make the room's map connection in that direction point to the
32
For example, here is a closed and locked door, blocking the
33
way into the 'Ruins' shrine:
35
Object Corridor "Stooped Corridor"
36
with description "A low, square-cut corridor, running north to south,
40
Object -> StoneDoor "stone door"
41
with description "It's just a big stone door.",
42
name "door" "massive" "big" "stone" "yellow",
44
"Passage south is barred by a massive door of yellow stone.",
46
"The great yellow stone door to the south is open.",
50
has static door openable lockable locked;
53
Note that the door is <TT>static</TT> -- otherwise the player could pick it up and
54
walk away with it! The properties <TT>when_closed</TT> and <TT>when_open</TT> give
55
descriptions appropriate for the door in these two states.
59
Doors are rather one-way: they are only really present on one side. If
60
a door needs to be accessible (openable and lockable from either side),
61
a neat trick is to make it present in both locations and to fix the
62
<TT>door_to</TT> and <TT>door_dir</TT> to the right way round for whichever side the player
63
is on. Here, then, is a two-way door:
65
Object -> StoneDoor "stone door"
66
with description "It's just a big stone door.",
67
name "door" "massive" "big" "stone" "yellow",
69
"The passage is barred by a massive door of yellow stone.",
71
"The great yellow stone door is open.",
73
[; if (location==Corridor) return Shrine; return Corridor; ],
75
[; if (location==Shrine) return n_to; return s_to; ],
77
found_in Corridor Shrine,
78
has static door openable lockable locked;
81
where <TT>Corridor</TT> has <TT>s_to</TT> set to <TT>StoneDoor</TT>, and <TT>Shrine</TT> has
82
<TT>n_to</TT> set to <TT>StoneDoor</TT>. The door can now be opened, closed, entered,
83
locked or unlocked from either side. We could also make <TT>when_open</TT>
84
and <TT>when_closed</TT> into routines to print different descriptions of the
88
At first sight, it isn't obvious why doors have the <TT>door_dir</TT>
90
property. Why does a door need to know which way it faces? The point is
91
that two different actions cause the player to go through the door.
92
Suppose the door is in the south wall. The player may type "go south'',
93
which directly causes the action <TT>Go s_obj</TT>. Or the player may "enter
94
door'' or "go through door'', causing <TT>Enter the_door</TT>. Provided the
95
door is actually open, the <TT>Enter</TT> action then looks at the door's
96
<TT>door_dir</TT> property, finds that the door faces south and generates
97
the action <TT>Go s_obj</TT>. Thus, however the player tries to go through
98
the door, it is the <TT>Go</TT> action that finally results.
101
This has an important consequence: if you put <TT>before</TT> and <TT>after</TT>
102
routines on the <TT>Enter</TT> action for the <TT>StoneDoor</TT>, they only apply to
103
a player typing "enter door" and not to one just typing "south". So
104
one safe way is to trap the <TT>Go</TT> action. A neater method is to
105
put some code into a <TT>door_to</TT> routine. If a <TT>door_to</TT>
106
routine returns 0 instead of a room, then the player is told that
107
the door "leads nowhere'' (like the famous broken bridge of Avignon).
108
If <TT>door_to</TT> returns 1, or 'true', then the library stops the action
109
on the assumption that something has happened and the player has been
113
<P><TR><TD Valign="top"><IMG SRC="icons/exercise.gif" ALT="??"><TD bgcolor="#FBB9AC"><A NAME="ex13"><B>EXERCISE 13:</B><BR>(link to <A HREF="answers1/answer13.html">the answer</A>)<TR><TD><TD> Create a plank bridge across a chasm, which collapses if
114
the player walks across it while carrying
118
<P><TR><TD Valign="top"><IMG SRC="icons/refs.gif" ALT="*"><TD bgcolor="#EEEEEE"><B>REFERENCES:</B><BR><SMALL> 'Advent' is especially rich in two-way doors: the steel grate
119
in the streambed, two bridges (one of crystal, the other of rickety
120
wood) and a door with rusty hinges. See also the iron gate in 'Balances'.
122
<HR><A HREF="contents.html">Contents</A> / <A HREF="section11.html">Back</A> / <A HREF="section13.html">Forward</A> <BR>
123
<A HREF="chapter1.html">Chapter I</A> / <A HREF="chapter2.html">Chapter II</A> / <A HREF="chapter3.html">Chapter III</A> / <A HREF="chapter4.html">Chapter IV</A> / <A HREF="chapter5.html">Chapter V</A> / <A HREF="chapter6.html">Chapter VI</A> / <A HREF="chapterA.html">Appendix</A><HR><SMALL><I>Mechanically translated to HTML from third edition as revised 16 May 1997. Copyright © Graham Nelson 1993, 1994, 1995, 1996, 1997: all rights reserved.</I></SMALL></BODY></HTML>