Answer to Exercise 2

| ANSWER TO EXERCISE 2
    Object medicine "guaranteed child-proof medicine bottle" cupboard
      with name "medicine" "bottle",
           description "~Antidote only: no preventative effect.~",
           openup
           [;  give self open ~locked; "The bottle cracks open!";
           ],
      has  container openable locked;
Any other code in the game can send the message `medicine.openup()` to crack open the bottle. For brevity, this solution assumes that the bottle is always visible to the player when it is opened -- if not the printed message will be incongruous.

Back to the exercise in section 8

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