1
<HTML><HEAD><TITLE>Section A7: Library-defined objects and routines</TITLE></HEAD>
2
<BODY BGCOLOR="#FFFFFF">
4
<TR><TD Valign="top"><A HREF="contents.html">Contents</A><BR><A HREF="sectionA6.html">Back</A><BR><A HREF="sectionA8.html">Forward</A><TD bgcolor="#F5DEB3"><BLOCKQUOTE><H3>A7. Library-defined objects and routines</H3></BLOCKQUOTE><TR><TD><TD>
5
The library defines the following
10
<DT><B><TT>compass</TT></B><DD>
11
To contain the directions. A direction object provides a
12
<TT>door_dir</TT> property, and should have the <TT>direction</TT> attribute. A compass
13
direction with <TT>enterable</TT>, if there is one (which there usually isn't),
14
will have an <TT>Enter</TT> action converted to <TT>Go</TT>.
17
<DT><B><TT>n_obj, ...</TT></B><DD>
19
Both the object signifying the abstract concept of 'northness', and the
20
'north wall' of the current room. (Thus, if a player types "examine the
21
north wall'' then the action <TT>Examine n_obj</TT> will be generated.) Its
22
<TT>door_dir</TT> property holds the direction property it corresponds to (<TT>n_to</TT>).
23
The other such objects are <TT>s_obj</TT>, <TT>e_obj</TT>, <TT>w_obj</TT>, <TT>ne_obj</TT>, <TT>nw_obj</TT>,
24
<TT>se_obj</TT>, <TT>sw_obj</TT>, <TT>u_obj</TT>, <TT>d_obj</TT>, <TT>in_obj</TT> and <TT>out_obj</TT>.
25
Note that the parser understands "ceiling'' to refer to <TT>u_obj</TT> and "floor'' to refer to
26
<TT>d_obj</TT>. (<TT>in_obj</TT> and <TT>out_obj</TT> differ slightly, because "in'' and
27
"out'' are verbs with other effects in some cases; these objects should not
28
be removed from the <TT>compass</TT>.)
31
<DT><B><TT>thedark</TT></B><DD>
32
A pseudo-room representing 'being in darkness'. <TT>location</TT>
33
is then set to this room, but the player object is not moved to it. Its
34
<TT>description</TT> can be changed to whatever "It is dark here'' message is
38
<DT><B><TT>selfobj</TT></B><DD>
39
The default player-object. Code should never refer directly
40
to <TT>selfobj</TT>, but only to <TT>player</TT>, a variable whose value is usually indeed
41
<TT>selfobj</TT> but which might become <TT>green_frog</TT> if the player is transformed
45
<DT><B><TT>InformLibrary</TT></B><DD>
46
Represents the library. You never need to use
47
it, but it might sometimes be the value of <TT>sender</TT> when a message is received.
50
<DT><B><TT>InformParser</TT></B><DD>
51
Represents the parser.
55
The following routines are defined in the library and available for public
60
<DT><B><TT>Achieved(task)</TT></B><DD>
62
Indicate the <TT>task</TT> is achieved (which only
63
awards score the first time).
66
<DT><B><TT>AddToScope(obj)</TT></B><DD>
68
Used in an <TT>add_to_scope</TT> routine of an object to add another object
69
into scope whenever the first is in scope.
72
<DT><B><TT>AllowPushDir()</TT></B><DD>
74
Signal that an attempt to push an object from
75
one place to another should be allowed.
78
<DT><B><TT>CDefArt(obj)</TT></B><DD>
80
Print the capitalised definite article and
81
short name of <TT>obj</TT>. Equivalent to <TT>print (The) obj;</TT>.
84
<DT><B><TT>ChangeDefault(p,v)</TT></B><DD>
86
Changes the default value of property <TT>p</TT>. (But this won't
87
do anything useful to <TT>name</TT>.)
90
<DT><B><TT>ChangePlayer(obj,flag)</TT></B><DD>
92
Cause the player at the keyboard to
93
play as the given object, which must have a <TT>number</TT> property supplied. If
94
the <TT>flag</TT> is set to 1, then subsequently print messages like "(as Ford
95
Prefect)'' in room description headers. This routine, however, prints nothing
99
<DT><B><TT>DefArt(obj)</TT></B><DD>
101
Print the definite article and short name of
102
<TT>obj</TT>. Equivalent to <TT>print (the) obj;</TT>.
105
<DT><B><TT>DoMenu(text,R1,R2)</TT></B><DD>
107
Produce a menu, using the two routines given.
110
<DT><B><TT>EnglishNumber(x)</TT></B><DD>
112
Prints out <TT>x</TT> in English (e.g., "two hundred and seventy-seven").
115
<DT><B><TT>HasLightSource(obj)</TT></B><DD>
117
Returns true if <TT>obj</TT> 'has light'.
120
<DT><B><TT>InDefArt(obj)</TT></B><DD>
122
Print the indefinite article and short name
123
of <TT>obj</TT>. Equivalent to <TT>print (a) obj;</TT>.
126
<DT><B><TT>Locale(obj,tx1,tx2)</TT></B><DD>
128
Prints out the paragraphs of room description which would appear
129
if <TT>obj</TT> were the room: i.e., prints out descriptions of objects
130
in <TT>obj</TT> according to the usual rules. After describing the
131
objects which have their own paragraphs, a list is given of
132
the remaining ones. The string <TT>tx1</TT> is printed if there were
133
no previous paragraphs, and the string <TT>tx2</TT> otherwise.
134
(For instance, you might want "On the ledge you can see''
135
and "On the ledge you can also see''.) After the list, nothing
136
else is printed (not even a full stop) and the return value is
137
the number of objects in the list (possibly zero).
140
<DT><B><TT>LoopOverScope(R,actor)</TT></B><DD>
142
Calls routine <TT>R(obj)</TT> for each object <TT>obj</TT> in scope. <TT>actor</TT>
143
is optional: if it's given, then scope is calculated for the
144
given actor, not the player.
147
<DT><B><TT>NextWord()</TT></B><DD>
149
Returns the next dictionary word in the player's
150
input, moving the word number <TT>wn</TT> on by one. Returns 0
151
if the word is not in the dictionary or if the word stream has
155
<DT><B><TT>NextWordStopped()</TT></B><DD>
157
As <TT>NextWord</TT>, but returning -1 when the word stream has run out.
160
<DT><B><TT>NounDomain(o1,o2,type)</TT></B><DD>
162
This routine is one of the keystones of the parser: the objects
163
given are the domains to search through when parsing (almost
164
always the location and the actor) and the <TT>type</TT> indicates a
165
token. The only tokens safely usable are: 0: <TABLE Border><TR><TD><TT>noun</TT></TABLE>,
166
1: <TABLE Border><TR><TD><TT>held</TT></TABLE> and 6: <TABLE Border><TR><TD><TT>creature</TT></TABLE>. The routine parses
167
the best single object name it can from the current position
168
of <TT>wn</TT>. It returns 0 (no match), an object number or
169
the constant <TT>REPARSE_CODE</TT> (to indicate that it had to ask
170
a clarifying question: this reconstructed the input drastically
171
and the parser must begin all over again). <TT>NounDomain</TT> should
172
only be used by general parsing routines and these should
173
always return <TT>REPARSE_CODE</TT> if it does. Note that all of the
174
usual scope and name-parsing rules apply to the search performed
175
by <TT>NounDomain</TT>.
178
<DT><B><TT>ObjectIsUntouchable</TT></B><DD>
180
Determines whether any solid barrier (that is, any <TT>container</TT> that
181
is not <TT>open</TT>) lies between the player and <TT>obj</TT>. If <TT>flag</TT> is set,
182
this routine never prints anything; otherwise it prints a message
183
like "You can't, because ... is in the way.'' if any barrier is
184
found. Returns <TT>true</TT> if a barrier is found, <TT>false</TT> if not.
187
<DT><B><TT>OffersLight(obj)</TT></B><DD>
189
Returns true if <TT>obj</TT> 'offers light'.
192
<DT><B><TT>PlaceInScope(obj)</TT></B><DD>
194
Puts <TT>obj</TT> into scope for the parser.
197
<DT><B><TT>PlayerTo(place,flag)</TT></B><DD>
199
Move the player to <TT>place</TT>. Unless
200
<TT>flag</TT> is given and is 1, describe the player's surroundings.
203
<DT><B><TT>PrintShortName(obj)</TT></B><DD>
205
Print the short name of <TT>obj</TT>.
206
(This is protected against <TT>obj</TT> having a meaningless value.)
207
Equivalent to <TT>print (name) obj;</TT>.
210
<DT><B><TT>ScopeWithin(obj)</TT></B><DD>
212
Puts the contents of <TT>obj</TT> into scope,
213
recursing downward according to the usual scope rules.
216
<DT><B><TT>SetTime(time,rate)</TT></B><DD>
218
Set the game clock (a 24-hour clock) to the
219
given <TT>time</TT> (in seconds since the start of the day), to run at the given <TT>rate</TT> <I>r</I>:
221
means it does not run, if
223
then <I>r</I> seconds pass every turn,
228
turns pass every second.
231
<DT><B><TT>StartDaemon(obj)</TT></B><DD>
233
Makes the daemon of <TT>obj</TT> active, so
234
that its <TT>daemon</TT> routine will be called every turn.
237
<DT><B><TT>StartTimer(obj,time)</TT></B><DD>
239
Starts the timer of <TT>obj</TT>, set
240
to go off in <TT>time</TT> turns, at which time its <TT>time_out</TT> routine will be called
241
(it must provide a <TT>time_left</TT> property).
244
<DT><B><TT>StopDaemon(obj)</TT></B><DD>
246
Makes the daemon of <TT>obj</TT> inactive, so
247
that its <TT>daemon</TT> routine is no longer called.
250
<DT><B><TT>StopTimer(obj)</TT></B><DD>
252
Stops the timer of <TT>obj</TT>, so that
253
it won't go off after all.
256
<DT><B><TT>TestScope(obj,actor)</TT></B><DD>
258
Returns true if <TT>obj</TT> is in scope; otherwise false. <TT>actor</TT>
259
is optional: if it's given, then scope is calculated for the
260
given actor, not the player.
263
<DT><B><TT>TryNumber(wordnum)</TT></B><DD>
265
Tries to parse the word at <TT>wordnum</TT> as a
266
number (recognising decimal numbers and English ones from "one'' to
267
"twenty''), returning
269
if it fails altogether, or the number.
270
Values exceeding 10000 are rounded down to 10000.
273
<DT><B><TT>UnsignedCompare(a,b)</TT></B><DD>
275
Returns 1 if <I>a</I> greater than <I>b</I>, 0 if <I>a</I> equals <I>b</I> and -1 if <I>a</I> less than <I>b</I>,
276
regarding <I>a</I> and <I>b</I> as unsigned
277
numbers between 0 and 65535 (or <TT>$ffff</TT>). (The usual <TT>></TT> condition performs
278
a signed comparison.)
281
<DT><B><TT>WordAddress(n)</TT></B><DD>
283
Returns the byte array containing the raw text of the <I>n</I>-th
284
word in the word stream.
287
<DT><B><TT>WordLength(n)</TT></B><DD>
289
Returns the length of the raw text of the <I>n</I>-th
290
word in the word stream.
293
<DT><B><TT>WriteListFrom(obj,s)</TT></B><DD>
295
Write a list of <TT>obj</TT> and its
296
siblings, with the style being <TT>s</TT> (a bitmap of options).
299
<DT><B><TT>YesOrNo()</TT></B><DD>
301
Assuming that a question has already been printed,
302
wait for the player to type "yes'' or "no'', returning true or false
306
<DT><B><TT>ZRegion(value)</TT></B><DD>
308
Works out the type of <TT>value</TT>, if possible. Returns 1 if it's a valid
309
object number, 2 if a routine address, 3 if a string address and 0
312
<HR><A HREF="contents.html">Contents</A> / <A HREF="sectionA6.html">Back</A> / <A HREF="sectionA8.html">Forward</A> <BR>
313
<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>