| ANSWER TO EXERCISE 83 | |
|
For good measure, we'll combine this with the previous rule about moved objects being in scope in the dark. The following can be inserted into the 'Shell' game:
Object coal "dull coal" Blank_Room
with name "dull" "coal";
Object Dark_Room "Dark Room"
with description "An empty room with a west exit.",
each_turn
[; if (self has general) self.each_turn=0;
else "^You hear the breathing of a dwarf.";
],
w_to Blank_Room;
Object -> light_switch "light switch"
with name "light" "switch",
initial "On one wall is the light switch.",
after
[; SwitchOn: give Dark_Room light;
SwitchOff: give Dark_Room ~light;
],
has switchable static;
Object -> diamond "shiny diamond"
with name "shiny" "diamond"
has scored;
Object -> dwarf "dwarf"
with name "voice" "dwarf",
life
[; Order: if (action==##SwitchOn && noun==light_switch)
{ give Dark_Room light general;
give light_switch on; "~Right you are, squire.~";
}
],
has animate;
[ InScope person i;
if (parent(person)==Dark_Room)
{ if (person==dwarf Dark_Room has general)
PlaceInScope(light_switch);
}
if (person==player && location==thedark)
objectloop (i near player)
if (i has moved i==dwarf)
PlaceInScope(i);
rfalse;
];
Note that the routine puts the light switch in scope for the dwarf --
if it didn't, the dwarf would not be able to understand
"dwarf, turn light on", and that was the whole point.}
As mentioned in the definition above, each object has the ability
to drag other objects into scope whenever it is in scope. This is
especially useful for giving objects component parts: e.g., giving a
washing-machine a temperature dial. (The dial can't be a child
object because that would throw it in with the clothes: and it ought to be
attached to the machine in case the machine is moved from place to place.)
For this purpose, the property add_to_scope may contain a list of
objects to add.
|