1
<HTML><HEAD><TITLE>Answer to Exercise 87</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 87</B><TR><TD><TD>
7
Firstly, create an attribute <TT>is_key</TT> and give it to all the keys in
12
print "(with ", (the) assumed_key, ")^"; <<Lock noun assumed_key>>;
14
[ DefaultLockTest i count;
15
if (noun hasnt lockable) rfalse;
16
objectloop (i in player)
17
if (i has is_key) { count++; assumed_key = i; }
18
if (count==1) rtrue; rfalse;
20
Extend "lock" first * noun = DefaultLockTest -> DefaultLock;
23
(and similar code for "unlock''). Note that "lock strongbox''
24
is matched by this new grammar line only if the player only has one
25
key: the <TT>DefaultLock strongbox</TT> action is generated: which is
26
converted to, say, <TT>Lock strongbox brass_key</TT>.
28
<HR>Back to <A HREF="../section29.html#ex87">the exercise in section 29</A><HR>
29
<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>