Contents
Back
Forward

13. Switchable objects

Steven: 'Well, what does this do?' Doctor: 'That is the dematerialising control. And that over yonder is the horizontal hold. Up there is the scanner, these are the doors, that is a chair with a panda on it. Sheer poetry, dear boy. Now please stop bothering me.'

...Dennis Spooner, The Time Meddler, Dr Who, serial 17 (1965)

Objects can also be switchable. This means they can be turned off or on, as if they had some kind of switch on them. The object has the attribute on if it's on. For example:

Object searchlight "Gotham City searchlight" skyscraper
  with name "search" "light" "template", article "the",
       description "It has some kind of template on it.",
       when_on "The old city searchlight shines out a bat against
                the feather-clouds of the darkening sky.",
       when_off "The old city searchlight, neglected but still
                 functional, sits here."
  has  switchable static;
Something more portable would come in handy for the explorer of 'Ruins', who would hardly have embarked on his expedition without a decent light source...
Object sodium_lamp "sodium lamp"
  with name "sodium" "lamp" "heavy",
       describe
       [;  if (self hasnt on) 
               "^The sodium lamp squats heavily on the ground.";
          "^The sodium lamp squats on the ground, burning away.";
       ],
       battery_power 40,
       before
       [;  Examine: print "It is a heavy-duty archaeologist's lamp, ";
               if (self hasnt on) "currently off.";
               if (self.battery_power < 10) "glowing a dim yellow.";
               "blazing with brilliant yellow light.";
           Burn: <<SwitchOn self>>;
           SwitchOn:
               if (self.battery_power <= 0)
                  "Unfortunately, the battery seems to be dead.";
               if (parent(self) hasnt supporter && self notin location)
                  "The lamp must be securely placed before being lit.";
           Take, Remove:
               if (self has on)
                  "The bulb's too delicate and the metal frame's too
                   hot to lift the lamp while it's switched on.";
       ],
       after
       [;  SwitchOn: give self light;
           SwitchOff: give self ~light;
       ],
  has  switchable;
The 'Ruins' lamp will eventually be a little more complicated, with a daemon to make the battery power run down and to extinguish the lamp when it runs out; and it will be pushable from place to place, making it not quite as useless as the player will hopefully think at first.

/\ A point to note is that this time the when_on and when_off properties haven't been used to describe the lamp when it's on the ground: this is because once an object has been held by the player, it's normally given only a perfunctory mention in room descriptions ("You can also see a sodium lamp and a grape here.''). But the describe property has priority over the whole business of how objects are described in room descriptions. When it returns true, as above, the usual description process does nothing further. For much more on room descriptions, see Section 22.

*REFERENCES:
The original switchable object was the brass lamp from 'Advent' (which also provides verbs "on'' and "off'' to switch it). (The other example games are generally pre-electric in setting.)


Contents / Back / Forward
Chapter I / Chapter II / Chapter III / Chapter IV / Chapter V / Chapter VI / Appendix
Mechanically translated to HTML from third edition as revised 16 May 1997. Copyright © Graham Nelson 1993, 1994, 1995, 1996, 1997: all rights reserved.