??ANSWER TO EXERCISE 13

The "plank breaking'' rule is implemented here in its door_to routine. Note that this returns 'true' after killing the player.

Object -> PlankBridge "plank bridge"
  with description "Extremely fragile and precarious.",
       name "precarious" "fragile" "wooden" "plank" "bridge",
       when_open
           "A precarious plank bridge spans the chasm.",
       door_to
       [;  if (children(player)~=0)
           {   deadflag=1;
              "You step gingerly across the plank, which bows under
               your weight. But your meagre possessions are the straw
               which breaks the camel's back! There is a horrid crack...";
           }
           print "You step gingerly across the plank, grateful that
                  you're not burdened.^";
           if (location==NearSide) return FarSide; return NearSide;
       ],
       door_dir
       [;  if (location==NearSide) return s_to; return n_to;
       ],
       found_in NearSide FarSide,
  has  static door open;
There might be a problem with this solution if your game also contained a character who wandered about, and whose code was clever enough to run door_to routines for any doors it ran into. If so, door_to could perhaps be modified to check that the actor is the player.

Back to the exercise in section 12
Mechanically translated to HTML from third edition as revised 16 May 1997. Copyright © Graham Nelson 1993, 1994, 1995, 1996, 1997: all rights reserved.