Inform - Resources - Examples

Back to List

Inventory
Complete

Backward
Forward

Plain
Coloured
Gaudy

This code
in plain text

Browsing Toyshop.inf

Matchbook (lines 247-340)

247  ! >MA  This is a matchbook of five matches, which is quite simple in that you
248  !      can only actually have one match at a time: otherwise, it's quite
249  !      a full implementation.  Note that the inventory lines for the match
250  !      and the matchbook are coded here.  Note also that the "match" object
251  !      returns to the book even when the book is empty, so that the parser
252  !      will still understand requests for matches - which the "before" rule,
253  !      which automatically removes matches when needed, can then turn down.
254  !
255  !      The matchbook has a daemon whose job is to tidy up lost matches.  One
256  !      might expect this rule to be coded with an "after" routine, to trap
257  !      the player dropping matches.  But suppose there were a magpie in the
258  !      game, and it flew down and stole the match but left the matchbook!
259  !      As it happens there isn't, but this is better form.
260  ! ----------------------------------------------------------------------------
261   
262  Object -> matchbook "matchbook"
263    with name "matchbook" "book" "matches",
264         number 5,
265         before
266         [; Burn: if (match has light)
267                  {   remove match; remove matchbook;
268                      "What a waste of matches!";
269                  }
270         ],
271         invent
272         [;  if (inventory_stage==2)
273             {   switch(self.number)
274                 {   0: print " (empty)";
275                     1: print " (1 match left)";
276                     default: print " (", self.number, " matches left)";
277                 }
278             }
279         ],
280         description
281         [;  print "The cover advertisement reads 
282                    ~Curses - Adventure of a Lunchtime~. The book ";
283             switch(self.number)
284             {   0: "is empty.";
285                 1: "has a single match left.";
286                 default:
287                     print_ret "contains ", self.number, " matches.";
288             }
289         ],
290         daemon
291         [;   if (match notin matchbook && match notin player)
292              {   move match to matchbook;
293                  if (match has light)
294                  {   give match ~light; StopTimer(match); }
295                  StopDaemon(self);
296              }
297         ],
298    has  transparent;
299   
300  Object -> -> match "match"
301    with parse_name
302         [ i j;   if (self has light) j='burning'; else j='unlit';
303                  while (NextWord()=='match' or j) i++;
304                  return i;
305         ],
306         article "an",
307         before
308         [ i; if (self in matchbook)
309              {   i=matchbook.number;
310                  if (i==0) "There are no matches left in the book.";
311                  i--; matchbook.number=i;
312                  move self to player; StartDaemon(matchbook);
313                  print "(taking a match from the book, which ";
314                  if (i==0) print "is now empty)^";
315                  if (i==1) print "has one more left)^";
316                  if (i>1)  print "has ", i, " left)^";
317                  self.article = "an";
318              }
319              Take, Remove: if (self in player) "Done.";
320              Burn:
321                  if (self has light) "The match is already alight.";
322                  if (matchbook notin player)
323                     "You need the matchbook to strike the match.";
324                  give self light; StartTimer(self, 2+random(3));
325                  self.article = "a";
326                  "You strike the match.";
327         ],
328         short_name
329         [;   if (self has light) print "burning match";
330                             else print "unlit match";
331              rtrue;
332         ],
333   
334         time_left,
335         time_out
336         [;   move self to matchbook; give self ~light;
337              "^You drop the match as the flame reaches your finger.";
338         ];
339   
340  ! ----------------------------------------------------------------------------


Last updated 23 June 2004. This web site has not been fully supported since April 2008. Information may be out of date. This page was originally managed by Graham Nelson (graham@gnelson.demon.co.uk) assisted by C Knight.