! >MA This is a matchbook of five matches, which is quite simple in that you ! can only actually have one match at a time: otherwise, it's quite ! a full implementation. Note that the inventory lines for the match ! and the matchbook are coded here. Note also that the "match" object ! returns to the book even when the book is empty, so that the parser ! will still understand requests for matches - which the "before" rule, ! which automatically removes matches when needed, can then turn down. ! ! The matchbook has a daemon whose job is to tidy up lost matches. One ! might expect this rule to be coded with an "after" routine, to trap ! the player dropping matches. But suppose there were a magpie in the ! game, and it flew down and stole the match but left the matchbook! ! As it happens there isn't, but this is better form. ! ---------------------------------------------------------------------------- Object -> matchbook "matchbook" with name "matchbook" "book" "matches", number 5, before [; Burn: if (match has light) { remove match; remove matchbook; "What a waste of matches!"; } ], invent [; if (inventory_stage==2) { switch(self.number) { 0: print " (empty)"; 1: print " (1 match left)"; default: print " (", self.number, " matches left)"; } } ], description [; print "The cover advertisement reads ~Curses - Adventure of a Lunchtime~. The book "; switch(self.number) { 0: "is empty."; 1: "has a single match left."; default: print_ret "contains ", self.number, " matches."; } ], daemon [; if (match notin matchbook && match notin player) { move match to matchbook; if (match has light) { give match ~light; StopTimer(match); } StopDaemon(self); } ], has transparent; Object -> -> match "match" with parse_name [ i j; if (self has light) j='burning'; else j='unlit'; while (NextWord()=='match' or j) i++; return i; ], article "an", before [ i; if (self in matchbook) { i=matchbook.number; if (i==0) "There are no matches left in the book."; i--; matchbook.number=i; move self to player; StartDaemon(matchbook); print "(taking a match from the book, which "; if (i==0) print "is now empty)^"; if (i==1) print "has one more left)^"; if (i>1) print "has ", i, " left)^"; self.article = "an"; } Take, Remove: if (self in player) "Done."; Burn: if (self has light) "The match is already alight."; if (matchbook notin player) "You need the matchbook to strike the match."; give self light; StartTimer(self, 2+random(3)); self.article = "a"; "You strike the match."; ], short_name [; if (self has light) print "burning match"; else print "unlit match"; rtrue; ], time_left, time_out [; move self to matchbook; give self ~light; "^You drop the match as the flame reaches your finger."; ]; ! ----------------------------------------------------------------------------