| ANSWER TO EXERCISE 87 | |
|
Firstly, create an attribute is_key and give it to all the keys in the game. Then:
Global assumed_key;
[ DefaultLockSub;
print "(with ", (the) assumed_key, ")^"; <<Lock noun assumed_key>>;
];
[ DefaultLockTest i count;
if (noun hasnt lockable) rfalse;
objectloop (i in player)
if (i has is_key) { count++; assumed_key = i; }
if (count==1) rtrue; rfalse;
];
Extend "lock" first * noun = DefaultLockTest -> DefaultLock;
(and similar code for "unlock''). Note that "lock strongbox''
is matched by this new grammar line only if the player only has one
key: the DefaultLock strongbox action is generated: which is
converted to, say, Lock strongbox brass_key.
|