1
<HTML><HEAD><TITLE>Answer to Exercise 86</TITLE></HEAD>
2
<BODY BGCOLOR="#FFFFFF">
3
<TABLE><TR><TD Valign="top"><IMG SRC="../icons/exercise.gif" ALT="??"><TD bgcolor="#FAA89B"><B>ANSWER TO EXERCISE 86</B><TR><TD><TD>
7
The label object itself is not too bad:
9
Object -> label "red sticky label"
10
with name "red" "sticky" "label",
15
{ print "(first removing the label from ",
16
(the) self.number, ")^"; self.number=0; move self to player;
18
if (second==self) "That would only make a red mess.";
19
self.number=second; remove self;
20
print_ret "You affix the label to ", (the) second, ".";
23
[ x; x=self.number; if (x==0) rfalse;
24
Look: if (x in location)
25
print "^The red sticky label is stuck to ", (the) x, ".^";
27
print "^The red sticky label is stuck to ", (the) x, ".^";
30
[; if (parent(self)~=0) self.number=0; ];
33
Note that <TT>label.number</TT> holds the object the label is stuck to, or
34
0 if it's unstuck: and that when it is stuck, it is removed from the
35
object tree. It therefore has to be moved into scope, so we need the
36
rule: if the labelled object is in scope, then so is the label.
39
[ InScope actor i1 i2;
40
if (label.number==0) rfalse; if (disable_self==1) rfalse;
42
i1 = TestScope(label, actor);
43
i2 = TestScope(label.number, actor);
46
if (i2~=0) PlaceInScope(label);
51
This routine has two interesting points: firstly, it disables itself
52
while testing scope (since otherwise the game would go into an endless
53
recursion), and secondly it only puts the label in scope if it isn't
54
already there. This is just a safety precaution to prevent the label
55
reacting twice to actions (and isn't really necessary since the label
56
can't already be in scope, but is included for the sake of example).
58
<HR>Back to <A HREF="../section28.html#ex86">the exercise in section 28</A><HR>
59
<SMALL><I>Mechanically translated to HTML from third edition as revised 16 May 1997. Copyright © Graham Nelson 1993, 1994, 1995, 1996, 1997: all rights reserved.</I></SMALL></BODY></HTML>