~ubuntu-branches/ubuntu/vivid/inform/vivid

« back to all changes in this revision

Viewing changes to html/sectionA7.html

  • Committer: Bazaar Package Importer
  • Author(s): Jan Christoph Nordholz
  • Date: 2008-05-26 22:09:44 UTC
  • mfrom: (2.1.1 lenny)
  • Revision ID: james.westby@ubuntu.com-20080526220944-ba7phz0d1k4vo7wx
Tags: 6.31.1+dfsg-1
* Remove a considerable number of files from the package
  due to unacceptable licensing terms.
* Repair library symlinks.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
<HTML><HEAD><TITLE>Section A7: Library-defined objects and routines</TITLE></HEAD>
2
 
<BODY BGCOLOR="#FFFFFF">
3
 
<TABLE><P>
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
6
 
special objects:
7
 
<P>
8
 
<P>
9
 
 
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>.
15
 
<P>
16
 
 
17
 
<DT><B><TT>n_obj, ...</TT></B><DD>
18
 
 
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>.)
29
 
<P>
30
 
 
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
35
 
desired.
36
 
<P>
37
 
 
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
42
 
into one.
43
 
<P>
44
 
 
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.
48
 
<P>
49
 
 
50
 
<DT><B><TT>InformParser</TT></B><DD>
51
 
Represents the parser.
52
 
<P>
53
 
 
54
 
<P>
55
 
The following routines are defined in the library and available for public
56
 
use:
57
 
<P>
58
 
<P>
59
 
 
60
 
<DT><B><TT>Achieved(task)</TT></B><DD>
61
 
 
62
 
Indicate the <TT>task</TT> is achieved (which only
63
 
awards score the first time).
64
 
<P>
65
 
 
66
 
<DT><B><TT>AddToScope(obj)</TT></B><DD>
67
 
 
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.
70
 
<P>
71
 
 
72
 
<DT><B><TT>AllowPushDir()</TT></B><DD>
73
 
 
74
 
Signal that an attempt to push an object from
75
 
one place to another should be allowed.
76
 
<P>
77
 
 
78
 
<DT><B><TT>CDefArt(obj)</TT></B><DD>
79
 
 
80
 
Print the capitalised definite article and
81
 
short name of <TT>obj</TT>.  Equivalent to <TT>print (The) obj;</TT>.
82
 
<P>
83
 
 
84
 
<DT><B><TT>ChangeDefault(p,v)</TT></B><DD>
85
 
 
86
 
Changes the default value of property <TT>p</TT>.  (But this won't
87
 
do anything useful to <TT>name</TT>.)
88
 
<P>
89
 
 
90
 
<DT><B><TT>ChangePlayer(obj,flag)</TT></B><DD>
91
 
 
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
96
 
itself.
97
 
<P>
98
 
 
99
 
<DT><B><TT>DefArt(obj)</TT></B><DD>
100
 
 
101
 
Print the definite article and short name of
102
 
<TT>obj</TT>.  Equivalent to <TT>print (the) obj;</TT>.
103
 
<P>
104
 
 
105
 
<DT><B><TT>DoMenu(text,R1,R2)</TT></B><DD>
106
 
 
107
 
Produce a menu, using the two routines given.
108
 
<P>
109
 
 
110
 
<DT><B><TT>EnglishNumber(x)</TT></B><DD>
111
 
 
112
 
Prints out <TT>x</TT> in English (e.g., "two hundred and seventy-seven").
113
 
<P>
114
 
 
115
 
<DT><B><TT>HasLightSource(obj)</TT></B><DD>
116
 
 
117
 
Returns true if <TT>obj</TT> 'has light'.
118
 
<P>
119
 
 
120
 
<DT><B><TT>InDefArt(obj)</TT></B><DD>
121
 
 
122
 
Print the indefinite article and short name
123
 
of <TT>obj</TT>.  Equivalent to <TT>print (a) obj;</TT>.
124
 
<P>
125
 
 
126
 
<DT><B><TT>Locale(obj,tx1,tx2)</TT></B><DD>
127
 
 
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).
138
 
<P>
139
 
 
140
 
<DT><B><TT>LoopOverScope(R,actor)</TT></B><DD>
141
 
 
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.
145
 
<P>
146
 
 
147
 
<DT><B><TT>NextWord()</TT></B><DD>
148
 
 
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
152
 
run out.
153
 
<P>
154
 
 
155
 
<DT><B><TT>NextWordStopped()</TT></B><DD>
156
 
 
157
 
As <TT>NextWord</TT>, but returning -1 when the word stream has run out.
158
 
<P>
159
 
 
160
 
<DT><B><TT>NounDomain(o1,o2,type)</TT></B><DD>
161
 
 
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>.
176
 
<P>
177
 
 
178
 
<DT><B><TT>ObjectIsUntouchable</TT></B><DD>
179
 
 
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.
185
 
<P>
186
 
 
187
 
<DT><B><TT>OffersLight(obj)</TT></B><DD>
188
 
 
189
 
Returns true if <TT>obj</TT> 'offers light'.
190
 
<P>
191
 
 
192
 
<DT><B><TT>PlaceInScope(obj)</TT></B><DD>
193
 
 
194
 
Puts <TT>obj</TT> into scope for the parser.
195
 
<P>
196
 
 
197
 
<DT><B><TT>PlayerTo(place,flag)</TT></B><DD>
198
 
 
199
 
Move the player to <TT>place</TT>.  Unless
200
 
<TT>flag</TT> is given and is 1, describe the player's surroundings.
201
 
<P>
202
 
 
203
 
<DT><B><TT>PrintShortName(obj)</TT></B><DD>
204
 
 
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>.
208
 
<P>
209
 
 
210
 
<DT><B><TT>ScopeWithin(obj)</TT></B><DD>
211
 
 
212
 
Puts the contents of <TT>obj</TT> into scope,
213
 
recursing downward according to the usual scope rules.
214
 
<P>
215
 
 
216
 
<DT><B><TT>SetTime(time,rate)</TT></B><DD>
217
 
 
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>:
220
 
r=0
221
 
means it does not run, if
222
 
r&#62;0
223
 
then <I>r</I> seconds pass every turn,
224
 
if
225
 
r&#60;0
226
 
then
227
 
-r
228
 
turns pass every second.
229
 
<P>
230
 
 
231
 
<DT><B><TT>StartDaemon(obj)</TT></B><DD>
232
 
 
233
 
Makes the daemon of <TT>obj</TT> active, so
234
 
that its <TT>daemon</TT> routine will be called every turn.
235
 
<P>
236
 
 
237
 
<DT><B><TT>StartTimer(obj,time)</TT></B><DD>
238
 
 
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).
242
 
<P>
243
 
 
244
 
<DT><B><TT>StopDaemon(obj)</TT></B><DD>
245
 
 
246
 
Makes the daemon of <TT>obj</TT> inactive, so
247
 
that its <TT>daemon</TT> routine is no longer called.
248
 
<P>
249
 
 
250
 
<DT><B><TT>StopTimer(obj)</TT></B><DD>
251
 
 
252
 
Stops the timer of <TT>obj</TT>, so that
253
 
it won't go off after all.
254
 
<P>
255
 
 
256
 
<DT><B><TT>TestScope(obj,actor)</TT></B><DD>
257
 
 
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.
261
 
<P>
262
 
 
263
 
<DT><B><TT>TryNumber(wordnum)</TT></B><DD>
264
 
 
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
268
 
-1000
269
 
if it fails altogether, or the number.
270
 
Values exceeding 10000 are rounded down to 10000.
271
 
<P>
272
 
 
273
 
<DT><B><TT>UnsignedCompare(a,b)</TT></B><DD>
274
 
 
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>&#62;</TT> condition performs
278
 
a signed comparison.)
279
 
<P>
280
 
 
281
 
<DT><B><TT>WordAddress(n)</TT></B><DD>
282
 
 
283
 
Returns the byte array containing the raw text of the <I>n</I>-th
284
 
word in the word stream.
285
 
<P>
286
 
 
287
 
<DT><B><TT>WordLength(n)</TT></B><DD>
288
 
 
289
 
Returns the length of the raw text of the <I>n</I>-th
290
 
word in the word stream.
291
 
<P>
292
 
 
293
 
<DT><B><TT>WriteListFrom(obj,s)</TT></B><DD>
294
 
 
295
 
Write a list of <TT>obj</TT> and its
296
 
siblings, with the style being <TT>s</TT> (a bitmap of options).
297
 
<P>
298
 
 
299
 
<DT><B><TT>YesOrNo()</TT></B><DD>
300
 
 
301
 
Assuming that a question has already been printed,
302
 
wait for the player to type "yes'' or "no'', returning true or false
303
 
accordingly.
304
 
<P>
305
 
 
306
 
<DT><B><TT>ZRegion(value)</TT></B><DD>
307
 
 
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
310
 
otherwise.
311
 
</TABLE>
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 &#169; Graham Nelson 1993, 1994, 1995, 1996, 1997: all rights reserved.</I></SMALL></BODY></HTML>