~ubuntu-branches/ubuntu/gutsy/inform/gutsy

« back to all changes in this revision

Viewing changes to html/section16.html

  • Committer: Bazaar Package Importer
  • Author(s): Mark Baker
  • Date: 2004-03-29 23:52:44 UTC
  • Revision ID: james.westby@ubuntu.com-20040329235244-fox1z1yv7d6vojoo
Tags: upstream-6.30
ImportĀ upstreamĀ versionĀ 6.30

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<HTML><HEAD><TITLE>Section 16: Living creatures and conversation</TITLE></HEAD>
 
2
<BODY BGCOLOR="#FFFFFF">
 
3
<TABLE></SMALL>
 
4
<TR><TD><TD><P>
 
5
<TR><TD Valign="top"><A HREF="contents.html">Contents</A><BR><A HREF="section15.html">Back</A><BR><A HREF="section17.html">Forward</A><TD bgcolor="#F5DEB3"><BLOCKQUOTE><H3>16. Living creatures and conversation</H3></BLOCKQUOTE><TR><TD><TD>
 
6
<P>
 
7
 
 
8
<BLOCKQUOTE>
 
9
<BR>To know how to live is my trade and my art.
 
10
<BR><P>...Michel de Montaigne (<B>1533</B>--<B>1592</B>), <I>Essays</I></BLOCKQUOTE>
 
11
<P>
 
12
 
 
13
<BLOCKQUOTE>
 
14
<BR>Everything that can be said can be said clearly.
 
15
<BR><P>...Ludwig Wittgenstein (<B>1889</B>--<B>1951</B>), <I>Tractatus</I></BLOCKQUOTE>
 
16
<P>
 
17
 
 
18
 
 
19
This rummage through special kinds of objects finishes up with the most
 
20
sophisticated kind: living ones.  Note that the finer points of this
 
21
section, on the arts of conversation, require some knowledge of Chapter
 
22
V.
 
23
<P>
 
24
 
 
25
Animate objects, such as sea monsters, mad aunts or nasty little dwarves,
 
26
have a property called <TT>life</TT>.  This behaves somewhat like a <TT>before</TT>
 
27
or <TT>after</TT> routine, but only applies to the following actions:
 
28
<P>
 
29
 
 
30
<DL>
 
31
<DT><B><TT>Attack</TT></B><DD>
 
32
 
 
33
The player is making hostile advances...
 
34
<P>
 
35
<DT><B><TT>Kiss</TT></B><DD>
 
36
 
 
37
...or excessively friendly ones...
 
38
<P>
 
39
<DT><B><TT>WakeOther</TT></B><DD>
 
40
 
 
41
...or simply trying to rouse the creature from sleep.
 
42
<P>
 
43
<DT><B><TT>ThrowAt</TT></B><DD>
 
44
 
 
45
The player asked to throw <TT>noun</TT> at the creature.
 
46
<P>
 
47
<DT><B><TT>Give</TT></B><DD>
 
48
 
 
49
The player asked to give <TT>noun</TT> to the creature...
 
50
<P>
 
51
<DT><B><TT>Show</TT></B><DD>
 
52
 
 
53
...or, tantalisingly, just to show it.
 
54
<P>
 
55
<DT><B><TT>Ask</TT></B><DD>
 
56
 
 
57
The player asked about something.  Just as with a "consult''
 
58
topic (see <A HREF="section15.html">Section 15</A> passim), the variables <TT>consult_from</TT>
 
59
and <TT>consult_words</TT> are set up to indicate which words the
 
60
object might like to think about.  (In addition, <TT>second</TT>
 
61
holds the dictionary value for the first word which isn't
 
62
<TT>'the'</TT>, but this is much cruder.)
 
63
<P>
 
64
<DT><B><TT>Tell</TT></B><DD>
 
65
 
 
66
Likewise, the player is trying to tell the creature about
 
67
something.  The topic is set up just as for <TT>Ask</TT> (that is,
 
68
<TT>consult_from</TT> and <TT>consult_words</TT> are set, and <TT>second</TT>
 
69
also holds the first interesting word).
 
70
<DT><B><TT>Answer</TT></B><DD>
 
71
 
 
72
This can happen in two ways.  One is if the player types "answer <I><B>&#60;some text&#62;</B></I>
 
73
to troll" or "say <I><B>&#60;some text&#62;</B></I> to troll''; the other is if he gives an
 
74
order which the parser can't sort out, such as
 
75
"troll, og south", and which the <TT>orders</TT> property hasn't handled
 
76
already.  Once again, variables are set as if it
 
77
were a "consult'' topic.  (In addition, <TT>noun</TT> is set to the
 
78
first word, and an attempt to read the text as a number is
 
79
stored in the variable <TT>special_number</TT>: for instance,
 
80
"computer, 143" will cause <TT>special_number</TT> to be set to
 
81
143.)
 
82
<P>
 
83
<DT><B><TT>Order</TT></B><DD>
 
84
 
 
85
This catches any 'orders' which aren't
 
86
handled by the <TT>orders</TT> property (see below); <TT>action</TT>,
 
87
<TT>noun</TT> and <TT>second</TT> are set up as usual. 
 
88
</DL>
 
89
<P>
 
90
 
 
91
If the <TT>life</TT> routine doesn't exist, or returns false, events take their
 
92
usual course.  <TT>life</TT> routines tend to be quite lengthy, even for
 
93
relatively static characters such as the priest who stands in
 
94
the 'Ruins' Shrine:
 
95
<PRE>
 
96
Object -&#62; priest "mummified priest"
 
97
  with name "mummified" "priest",
 
98
       description
 
99
          "He is desiccated and hangs together only by will-power.  Though
 
100
           his first language is presumably local Mayan, you have the curious
 
101
           instinct that he will understand your speech.",
 
102
       initial "Behind the slab, a mummified priest stands waiting, barely
 
103
           alive at best, impossibly venerable.",
 
104
       life
 
105
       [; Answer: "The priest coughs, and almost falls apart.";
 
106
          Ask:     switch(second)
 
107
                   {   'dictionary', 'book':
 
108
                            if (dictionary has general)
 
109
                                "~The ~bird~ glyph... very funny.~";
 
110
                           "~A dictionary? Really?~";
 
111
                       'glyph', 'glyphs', 'mayan', 'dialect':
 
112
                           "~In our culture, the Priests are ever literate.~";
 
113
                       'king', 'tomb', 'shrine', 'temple', 'altar', 'slab':
 
114
                           "~The King (life! prosperity! happiness!) is buried
 
115
                            deep under this Shrine, where you will never go.~";
 
116
                   }
 
117
                   "~You must find your own answer.~";
 
118
          Tell:   "The priest has no interest in your sordid life.";
 
119
          Attack, Kiss:  remove self;
 
120
                  "The priest desiccates away into dust until nothing
 
121
                   remains, not a breeze nor a bone.";
 
122
          ThrowAt: move noun to location; &#60;&#60;Attack self&#62;&#62;;
 
123
          Show, Give:
 
124
                   if (noun==dictionary &#38;&#38; dictionary hasnt general)
 
125
                   {   give dictionary general;
 
126
                      "The priest reads a little of the book, laughing
 
127
                       in a hollow, whispering way.  Unable to restrain
 
128
                       his mirth, he scratches in a correction somewhere
 
129
                       before returning the book.";
 
130
                   }
 
131
                  "The priest is not very interested in earthly things.";
 
132
       ],
 
133
  has  animate;
 
134
</PRE>
 
135
 
 
136
(Some of the <TT>Ask</TT> topics are omitted for brevity.)
 
137
Of course an <TT>animate</TT> object still has <TT>before</TT> and <TT>after</TT> routines
 
138
like any other, so you can trap many other kinds of behaviour.
 
139
Animate creatures can also <TT>react_before</TT> and <TT>react_after</TT>, and it's
 
140
here that these properties really come into their own:
 
141
 
 
142
<PRE>
 
143
       react_before
 
144
       [; Drop: if (noun==satellite_gadget)
 
145
             print "~I wouldn't do that, Mr Bond,~ says Blofeld.^^";
 
146
          Shoot: remove beretta;
 
147
            "As you draw, Blofeld snaps his fingers and a giant
 
148
             magnet snatches the gun from your hand.  It hits the
 
149
             ceiling with a clang.  Blofeld silkily strokes his cat.";
 
150
       ];
 
151
</PRE>
 
152
 
 
153
 
 
154
If Blofeld moves from place to place, these rules move with him.
 
155
<P>
 
156
 
 
157
<P><TR><TD Valign="top"><IMG SRC="icons/exercise.gif" ALT="??"><TD bgcolor="#FBB9AC"><A NAME="ex18"><B>EXERCISE 18:</B><BR>(link to <A HREF="answers1/answer18.html">the answer</A>)<TR><TD><TD> Arrange for a bearded psychiatrist to place the player
 
158
under observation, occasionally mumbling insights such as
 
159
"Subject puts green cone on table.
 
160
Interesting.''
 
161
<P>
 
162
 
 
163
 
 
164
Another example is the coiled snake from 'Balances', which
 
165
shows that even the tiniest <TT>life</TT> routine can be adequate for an animal:
 
166
<PRE>
 
167
Object -&#62; snake "hissing snake"
 
168
  with name "hissing" "snake",
 
169
       initial "Tightly coiled at the edge of the chasm is a hissing snake.",
 
170
       life [; "The snake hisses angrily!"; ],
 
171
  has  animate;
 
172
</PRE>
 
173
 
 
174
 
 
175
<P>
 
176
 
 
177
<P><TR><TD Valign="top"><IMG SRC="icons/dbend.gif" ALT="/\"><TD bgcolor="#EEEEEE"><SMALL> When writing general code to deal with <TT>animate</TT> creatures,
 
178
it's sometimes convenient to have a system worked out for printing
 
179
pronouns such as "her'' and "He''.  See <A HREF="section22.html">Section 22</A> for one way to do this.
 
180
</SMALL>
 
181
<TR><TD><TD><P>
 
182
 
 
183
 
 
184
Sometimes creatures should be <TT>transparent</TT>, sometimes not.  Consider these
 
185
two cases of <TT>animate</TT> characters, for instance:
 
186
 
 
187
<P> --  an urchin with something bulging inside his jacket pocket;
 
188
<P> --  a hacker who has a bunch of keys hanging off his belt.
 
189
<P>
 
190
 
 
191
 
 
192
The hacker is <TT>transparent</TT>, the urchin not.  That way the parser prevents
 
193
the player from referring to whatever the urchin is hiding, even if the
 
194
player has played the game before, and knows what is in there and what it's
 
195
called.  But the player can look at and be tantalised by the hacker's
 
196
keys.
 
197
<P>
 
198
<P>
 
199
 
 
200
 
 
201
When the player types in something like "pilot, fly south'',
 
202
the result is called an 'order': this is the corresponding idea to an
 
203
'action'.  (Indeed, if the player types "me, go south'' an
 
204
ordinary <TT>Go s_obj</TT> action is produced.)
 
205
<P>
 
206
 
 
207
The order is sent to the pilot's <TT>orders</TT> property, which may if
 
208
it wishes obey or react in some other way.  Otherwise, the standard
 
209
game rules will simply print something like "The pilot has better things
 
210
to do.''  The above priest is especially unhelpful:
 
211
<PRE>
 
212
       orders
 
213
       [;  Go: "~I must not leave the Shrine.~";
 
214
           NotUnderstood: "~You speak in riddles.~";
 
215
           default: "~It is not your orders I serve.~";
 
216
       ];
 
217
</PRE>
 
218
 
 
219
(The <TT>NotUnderstood</TT> clause is run when the parser couldn't
 
220
understand what the player typed: e.g., "priest, go onrth''.)
 
221
<P>
 
222
 
 
223
<P><TR><TD Valign="top"><IMG SRC="icons/dbend.gif" ALT="/\"><TD bgcolor="#EEEEEE"><SMALL> Something to bear in mind is that because the library regards
 
224
the words "yes'' and "no'' as being verbs in Inform, it understands
 
225
"delores, yes'' as being a <TT>Yes</TT> order.  (This can be a slight
 
226
nuisance, as "say yes to delores'' is treated differently: it gets
 
227
routed through the <TT>life</TT> routine as an <TT>Answer</TT>.)
 
228
</SMALL>
 
229
<TR><TD><TD><P>
 
230
 
 
231
<P><TR><TD Valign="top"><IMG SRC="icons/ddbend.gif" ALT="/\/\"><TD bgcolor="#EEEEEE"><SMALL> If the <TT>orders</TT> property returns false (or if there wasn't
 
232
an <TT>orders</TT> property in the first place), the order is sent either
 
233
to the <TT>Order:</TT> part of the <TT>life</TT> property (if it's understood)
 
234
or to the <TT>Answer:</TT> part (if it isn't).  (This is how all orders used to
 
235
be processed, and it's retained to avoid making reams of old Inform
 
236
code go wrong.)  If these also return false, a message like "X has
 
237
better things to do'' or "There is no reply'' is finally printed.
 
238
</SMALL>
 
239
<TR><TD><TD><P>
 
240
 
 
241
 
 
242
To clarify the various kinds of conversation:
 
243
 
 
244
<BR><TABLE Border><TR><TD> Command                      <TD> rule      <TD> <TT>action</TT>  <TD> <TT>noun</TT>    <TD> <TT>second</TT>   <TD> consult
 
245
<TR><TD> "orc, take axe''            <TD> <TT>order</TT>   <TD> <TT>Take</TT>    <TD> <TT>axe</TT>     <TD> <TT>0</TT>        <TD>
 
246
<TR><TD> "orc, yes''                 <TD> <TT>order</TT>   <TD> <TT>Yes</TT>     <TD> <TT>0</TT>       <TD> <TT>0</TT>        <TD>
 
247
<TR><TD> "ask orc for the shield''   <TD> <TT>order</TT>   <TD> <TT>Give</TT>    <TD> <TT>shield</TT>  <TD> <TT>player</TT>   <TD>
 
248
<TR><TD> "orc, troll''               <TD> <TT>order</TT>   <TD> <TT>NotU...</TT> <TD> <TT>'troll'</TT> <TD> <TT>orc</TT>      <TD> 3<SAMP>      </SAMP> 1
 
249
<TR><TD> "say troll to orc''         <TD> <TT>life</TT>    <TD> <TT>Answer</TT>  <TD> <TT>'troll'</TT> <TD> <TT>orc</TT>      <TD> 2<SAMP>      </SAMP> 1
 
250
<TR><TD> "answer troll to orc''      <TD> <TT>life</TT>    <TD> <TT>Answer</TT>  <TD> <TT>'troll'</TT> <TD> <TT>orc</TT>      <TD> 2<SAMP>      </SAMP> 1
 
251
<TR><TD> "orc, tell me about coins'' <TD> <TT>life</TT>    <TD> <TT>Ask</TT>     <TD> <TT>orc</TT>     <TD> <TT>'coins'</TT>  <TD> 6<SAMP>      </SAMP> 1
 
252
<TR><TD> "ask orc about the big troll'' <TD> <TT>life</TT> <TD> <TT>Ask</TT>     <TD> <TT>orc</TT>     <TD> <TT>'big'</TT>    <TD> 4<SAMP>      </SAMP> 3
 
253
<TR><TD> "ask orc about wyvern''     <TD> <TT>life</TT>    <TD> <TT>Ask</TT>     <TD> <TT>orc</TT>     <TD> <TT>0</TT>        <TD> 4<SAMP>      </SAMP> 1
 
254
<TR><TD> "tell orc about lost troll'' <TD> <TT>life</TT>   <TD> <TT>Tell</TT>    <TD> <TT>orc</TT>     <TD> <TT>'lost'</TT>   <TD> 4<SAMP>      </SAMP> 2
 
255
</TABLE>
 
256
where "wyvern'' is a word not mentioned anywhere in the program,
 
257
which is why its value is <TT>0</TT>.
 
258
<P>
 
259
 
 
260
<P><TR><TD Valign="top"><IMG SRC="icons/exercise.gif" ALT="??"><TD bgcolor="#FBB9AC"><A NAME="ex19"><B>EXERCISE 19:</B><BR>(link to <A HREF="answers1/answer19.html">the answer</A>)<TR><TD><TD>  In some ways, <TT>Answer</TT> and <TT>Tell</TT> are just too much trouble.
 
261
How can you make attempts to use these produce a message saying
 
262
"To talk to someone, try
 
263
'someone, something'.''?
 
264
 
 
265
<P>
 
266
 
 
267
<P>
 
268
 
 
269
Some objects are not alive as such, but can be spoken to: microphones,
 
270
tape recorders, voice-activated computers and so on.
 
271
It would be a nuisance to implement these as <TT>animate</TT>, since they have
 
272
none of the other characteristics of life: instead, they can be given
 
273
just the attribute <TT>talkable</TT> and <TT>orders</TT> and <TT>life</TT> properties to
 
274
deal with the resulting conversation.
 
275
<P>
 
276
 
 
277
<P><TR><TD Valign="top"><IMG SRC="icons/exercise.gif" ALT="??"><TD bgcolor="#FBB9AC"><A NAME="ex20"><B>EXERCISE 20:</B><BR>(link to <A HREF="answers1/answer20.html">the answer</A>)<TR><TD><TD> (Cf. 'Starcross'.)  Construct a computer responding to
 
278
"computer, theta is 180''.
 
279
 
 
280
<P>
 
281
 
 
282
<P>
 
283
<P><TR><TD Valign="top"><IMG SRC="icons/dbend.gif" ALT="/\"><TD bgcolor="#EEEEEE"><SMALL> The rest of this section starts to overlap much more with
 
284
Chapter V, and assumes a little familiarity with the parser.
 
285
</SMALL>
 
286
<TR><TD><TD><P>
 
287
 
 
288
<P><TR><TD Valign="top"><IMG SRC="icons/dbend.gif" ALT="/\"><TD bgcolor="#EEEEEE"><SMALL>  The <TT>NotUnderstood</TT> clause of <TT>orders</TT> is run when the
 
289
parser has got stuck parsing an order like "pilot, fly somersaults''.
 
290
The variable <TT>etype</TT> holds the parser error that would have been
 
291
printed out, had it been a command by the player himself.  See <A HREF="section29.html">Section 29</A>:
 
292
for instance, <TT>CANTSEE_PE</TT> would mean "the pilot can't see any such
 
293
object''.
 
294
</SMALL>
 
295
<TR><TD><TD><P>
 
296
 
 
297
<P><TR><TD Valign="top"><IMG SRC="icons/dbend.gif" ALT="/\"><TD bgcolor="#EEEEEE"><SMALL>
 
298
When the player issues requests to an <TT>animate</TT> or <TT>talkable</TT> object,
 
299
they're normally parsed exactly as if they were commands by the
 
300
player himself (except that the <TT>actor</TT> is now the person being
 
301
spoken to).  But sometimes one would rather they were parsed by
 
302
an entirely different grammar.  For instance, consider Zen, the
 
303
flight computer of an alien spacecraft.  It's inappropriate to
 
304
tell Zen to (say) pick up a teleport bracelet and the crew tend
 
305
to give commands more like:
 
306
<BLOCKQUOTE>
 
307
"Zen, set course for Centauro''<BR>
 
308
"Zen, speed standard by six''<BR>
 
309
"Zen, scan 360 orbital''<BR>
 
310
"Zen, raise the force wall''<BR>
 
311
"Zen, clear the neutron blasters for firing''<BR>
 
312
</BLOCKQUOTE>
 
313
 
 
314
This could mostly be implemented by adding verbs like "raise''
 
315
to the usual game grammar (see the 'Starcross' computer exercise
 
316
above), or by carefully trapping the <TT>Answer</TT> rule.  But this is
 
317
a nuisance, especially if about half the commands you want are
 
318
recognised as orders in the usual grammar but the other half aren't.
 
319
</SMALL>
 
320
<TR><TD><TD><P>
 
321
 
 
322
<TR><TD><TD bgcolor="#EEEEEE"><SMALL>
 
323
An <TT>animate</TT> or <TT>talkable</TT> object can therefore provide a <TT>grammar</TT>
 
324
routine (if it likes).  This is called at a time when the parser has
 
325
worked out the object that is being addressed and has set the variables
 
326
<TT>verb_num</TT> and <TT>verb_word</TT> (to the number of the 'verb' and its
 
327
dictionary entry, respectively: for example, in "orac, operate the
 
328
teleport'' <TT>verb_num</TT> would be 3 (because the comma counts as a
 
329
word on its own) and <TT>verb_word</TT> would be <TT>'operate'</TT>).  The <TT>grammar</TT>
 
330
routine can reply by returning:
 
331
<P>0. -- The parser carries on as usual.
 
332
<P>1. -- The <TT>grammar</TT> routine is saying it has done all the parsing necessary
 
333
itself, by hand (i.e., using <TT>NextWord</TT>, <TT>TryNumber</TT>, <TT>NounDomain</TT> and
 
334
the like): the variables <TT>action</TT>, <TT>noun</TT> and <TT>second</TT> must be set up
 
335
to contain the resulting order.
 
336
<P><TT>'verb'</TT> -- The parser ignores the usual grammar and instead works
 
337
through the grammar lines for the given verb (see below).
 
338
<P><TT>-'verb'</TT> -- Ditto, except that if none of those grammar lines work
 
339
then the parser goes back and tries the usual grammar as well.
 
340
<P>
 
341
 
 
342
 In addition, the <TT>grammar</TT> routine is free to
 
343
do some partial parsing of the early words provided it moves on
 
344
<TT>verb_num</TT> accordingly to show how much it's got through.
 
345
<P>
 
346
 
 
347
<P><TR><TD Valign="top"><IMG SRC="icons/dexercise.gif" ALT="??/\"><TD bgcolor="#FBB9AC"><A NAME="ex21"><B>EXERCISE 21:</B><BR>(link to <A HREF="answers1/answer21.html">the answer</A>)<TR><TD><TD> Implement Charlotte, a little girl who's playing
 
348
Simon Says (a game in which she only follows your instructions
 
349
if you remember to say "Simon says'' in front of them: so she'll
 
350
disobey "charlotte, wave'' but obey
 
351
"charlotte, simon says wave'').
 
352
 
 
353
<P>
 
354
 
 
355
<P><TR><TD Valign="top"><IMG SRC="icons/dexercise.gif" ALT="??/\"><TD bgcolor="#FBB9AC"><A NAME="ex22"><B>EXERCISE 22:</B><BR>(link to <A HREF="answers1/answer22.html">the answer</A>)<TR><TD><TD> Another of Charlotte's rules is that if you say a
 
356
number, she has to clap that many times.  Can you
 
357
play?
 
358
<P>
 
359
 
 
360
<P><TR><TD Valign="top"><IMG SRC="icons/dexercise.gif" ALT="??/\"><TD bgcolor="#FBB9AC"><A NAME="ex23"><B>EXERCISE 23:</B><BR>(link to <A HREF="answers1/answer23.html">the answer</A>)<TR><TD><TD> Regrettably, Dyslexic Dan has always mixed up the
 
361
words "take'' and "drop''.  Implement him
 
362
anyway.
 
363
<P>
 
364
 
 
365
<P><TR><TD Valign="top"><IMG SRC="icons/dbend.gif" ALT="/\"><TD bgcolor="#EEEEEE"><SMALL>  It's useful to know that if the player types a comma or a
 
366
full stop, then the parser cuts these out as separate words.  Because
 
367
of this, a dictionary word containing up to 7 letters and
 
368
then a comma or a full stop can never be matched by what the player
 
369
types.  Such a word is called an "untypeable verb'', and it's useful
 
370
to help a <TT>grammar</TT> routine to shunt parsing into a piece of game
 
371
grammar which the player can never use.
 
372
For instance, here's a way to implement the 'Starcross'
 
373
computer which doesn't involve creating foolish new actions.  We
 
374
create grammar:
 
375
<PRE>
 
376
[ Control;
 
377
  switch(NextWord())
 
378
  {   'theta': parsed_number=1; return 1;
 
379
      'phi':   parsed_number=2; return 1;
 
380
      'range': parsed_number=3; return 1;
 
381
      default: return -1;
 
382
  }
 
383
];
 
384
Verb "comp," * Control "is" number -&#62; SetTo;
 
385
</PRE>
 
386
 
 
387
And the computer itself needs properties
 
388
<PRE>
 
389
       grammar [; return 'comp,'; ],
 
390
       orders
 
391
       [;  SetTo:
 
392
               switch(noun)
 
393
               {   1: print "~Theta"; 2: print "~Phi"; 3: print "~Range"; }
 
394
               print_ret " set to ", second, ".~";
 
395
           default: "~Does not compute!~";
 
396
       ];
 
397
</PRE>
 
398
 
 
399
This may not look easier, but it's much more flexible, as the exercises
 
400
below will hopefully demonstrate.
 
401
</SMALL>
 
402
<TR><TD><TD><P>
 
403
 
 
404
<P><TR><TD Valign="top"><IMG SRC="icons/ddbend.gif" ALT="/\/\"><TD bgcolor="#EEEEEE"><SMALL> Another use for untypeable verbs is to create what might be
 
405
called 'fake fake actions'.  Recall that a fake action is one which
 
406
is never generated by the parser, and has no action routine.  Sometimes
 
407
(very rarely) you want a proper action but which still can't be
 
408
generated by the parser: the following example creates three.
 
409
<PRE>
 
410
Verb "actions." * -&#62; Prepare * -&#62; Simmer * -&#62; Cook;
 
411
</PRE>
 
412
 
 
413
The parser never uses "actions.'' in its ordinary grammar, so this
 
414
definition has the sole effect of creating three new actions:
 
415
<TT>Prepare</TT>, <TT>Simmer</TT> and <TT>Cook</TT>.
 
416
</SMALL>
 
417
<TR><TD><TD><P>
 
418
 
 
419
<P><TR><TD Valign="top"><IMG SRC="icons/ddexercise.gif" ALT="??/\/\"><TD bgcolor="#FBB9AC"><A NAME="ex24"><B>EXERCISE 24:</B><BR>(link to <A HREF="answers1/answer24.html">the answer</A>)<TR><TD><TD> How can you make a grammar extension to an ordinary
 
420
verb that will apply only to
 
421
Dan?
 
422
 
 
423
<P>
 
424
 
 
425
<P><TR><TD Valign="top"><IMG SRC="icons/dexercise.gif" ALT="??/\"><TD bgcolor="#FBB9AC"><A NAME="ex25"><B>EXERCISE 25:</B><BR>(link to <A HREF="answers1/answer25.html">the answer</A>)<TR><TD><TD> Make an alarm clock responding to "alarm, off'',
 
426
"alarm, on'' and "alarm, half past seven'' (the latter to
 
427
set its alarm time).
 
428
<P>
 
429
 
 
430
<P><TR><TD Valign="top"><IMG SRC="icons/dexercise.gif" ALT="??/\"><TD bgcolor="#FBB9AC"><A NAME="ex26"><B>EXERCISE 26:</B><BR>(link to <A HREF="answers1/answer26.html">the answer</A>)<TR><TD><TD> Implement a tricorder (from
 
431
Star Trek) which analyses nearby objects on a request like
 
432
"tricorder, the quartz stratum''.
 
433
<P>
 
434
 
 
435
<P><TR><TD Valign="top"><IMG SRC="icons/dexercise.gif" ALT="??/\"><TD bgcolor="#FBB9AC"><A NAME="ex27"><B>EXERCISE 27:</B><BR>(link to <A HREF="answers1/answer27.html">the answer</A>)<TR><TD><TD> And, for good measure, a replicator
 
436
responding to commands like "replicator, tea earl grey''
 
437
and "replicator, aldebaran brandy''.
 
438
 
 
439
<P>
 
440
 
 
441
<P><TR><TD Valign="top"><IMG SRC="icons/ddexercise.gif" ALT="??/\/\"><TD bgcolor="#FBB9AC"><A NAME="ex28"><B>EXERCISE 28:</B><BR>(link to <A HREF="answers1/answer28.html">the answer</A>)<TR><TD><TD> And a communications badge in contact with the ship's
 
442
computer, which answers questions like
 
443
"computer, where is Admiral Lebling''.
 
444
 
 
445
<P>
 
446
 
 
447
<P><TR><TD Valign="top"><IMG SRC="icons/ddexercise.gif" ALT="??/\/\"><TD bgcolor="#FBB9AC"><A NAME="ex29"><B>EXERCISE 29:</B><BR>(link to <A HREF="answers1/answer29.html">the answer</A>)<TR><TD><TD> Finally, construct the formidable flight computer
 
448
Zen.
 
449
<P>
 
450
 
 
451
<P><P><TR><TD><TD bgcolor="#EEEEEE"><SMALL>
 
452
The next two exercises really belong to <A HREF="section28.html">Section 28</A>, but are too useful
 
453
(for the "someone on the other end of a phone'' situation) to
 
454
bury far away.  Note that an alternative to these scope-hacking
 
455
tricks, if you just want to implement something like "michael,
 
456
tell me about the crystals'' (when Michael is at the other end of the
 
457
line), is to make the phone a <TT>talkable</TT> object and make the word
 
458
<TT>'michael'</TT> refer to the phone (using a <TT>parse_name</TT> routine).
 
459
<P>
 
460
 
 
461
For more on scope hacking, see <A HREF="section28.html">Section 28</A>.  Note that the variable <TT>scope_reason</TT>
 
462
is always set to the constant value <TT>TALKING_REASON</TT> when the game is trying
 
463
to work out who you wish to talk to: so it's quite easy to make the
 
464
scope different for conversational
 
465
purposes.
 
466
<P>
 
467
 
 
468
<P><TR><TD Valign="top"><IMG SRC="icons/dexercise.gif" ALT="??/\"><TD bgcolor="#FBB9AC"><A NAME="ex30"><B>EXERCISE 30:</B><BR>(link to <A HREF="answers1/answer30.html">the answer</A>)<TR><TD><TD> Via the main screen of the
 
469
Starship Enterprise, Captain Picard wants to see and talk to
 
470
Noslen Maharg, the notorious tyrant, who is down on the planet
 
471
Mrofni.  Make it so.
 
472
 
 
473
<P>
 
474
 
 
475
<P><TR><TD Valign="top"><IMG SRC="icons/ddexercise.gif" ALT="??/\/\"><TD bgcolor="#FBB9AC"><A NAME="ex31"><B>EXERCISE 31:</B><BR>(link to <A HREF="answers1/answer31.html">the answer</A>)<TR><TD><TD> Put the player in telepathic contact with
 
476
Martha, who is in a sealed room some distance away, but who has
 
477
a talent for telekinesis.  Martha should respond well to
 
478
"martha, look'', "ask martha about...'', "say yes to martha'',
 
479
"ask martha for red ball'', "martha, give me the red ball'' and
 
480
the like.
 
481
<P>
 
482
 
 
483
</SMALL><TR><TD><TD>
 
484
<P><TR><TD Valign="top"><IMG SRC="icons/refs.gif" ALT="*"><TD bgcolor="#EEEEEE"><B>REFERENCES:</B><BR><SMALL>
 
485
A much fuller example of a 'non-player character' is given in
 
486
the example game 'The Thief', by Gareth Rees (though it's
 
487
really an implementation of the gentleman in 'Zork', himself
 
488
an imitation of the pirate in 'Advent').  The thief is
 
489
capable of walking around, being followed, stealing things,
 
490
picking locks, opening doors and so on.
 
491
<BR> Other good definitions of <TT>animate</TT> objects to look at
 
492
are Christopher in 'Toyshop', who will stack up building blocks
 
493
on request; the kittens in 'Alice Through The Looking-Glass'; the
 
494
barker in 'Balances', and the cast of 'Advent': the little
 
495
bird, the snake, bear and dragon, the pirate and of course the
 
496
threatening little dwarves.
 
497
<BR> Following people means being able to refer to them after
 
498
they've left the room: see 'Follow my leader', also by Mr Rees,
 
499
or the library extension "follower.h'' by Andrew Clover.
 
500
<BR> See the Inform home page for a way round the <TT>Yes</TT>
 
501
awkwardness.
 
502
<BR> For parsing topics of conversation in advanced ways,
 
503
see the example game 'Encyclopaedia Frobozzica'
 
504
by Gareth Rees.
 
505
<BR> To see how much a good set of characters can do for a
 
506
game, try playing the prologue of 'Christminster'.
 
507
</SMALL>
 
508
<TR><TD><TD><P>
 
509
 
 
510
 
 
511
</TABLE>
 
512
<HR><A HREF="contents.html">Contents</A> / <A HREF="section15.html">Back</A> / <A HREF="section17.html">Forward</A> <BR>
 
513
<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>