Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

[TADS3] Mutually exclusive Wearable objects

4 views
Skip to first unread message

HappyEngineer

unread,
Aug 14, 2006, 12:25:52 AM8/14/06
to
How do I make Wearable objects mutually exclusive?

For instance, I might want to allow 3 different rings to be worn
simultaneously, but I wouldn't want to allow 3 different hats to be
worn simultaneously. How do I make it so that trying to put one hat on
causes any worn hat to be taken off first?

Greg Boettcher

unread,
Aug 14, 2006, 1:13:05 AM8/14/06
to

If you want the player to *automatically* remove one hat before putting
on another, you'd have to define a new precondition. The code below
seems to work, and is modeled on ObjOpenCondition, one of the library's
more easily understandable preconditions.

HTH...

Greg

class Hat: Wearable
dobjFor(Wear) {
// switch the order of these preconditions if you want
preCond = [notWearingHat, objHeld]
}
;

greenHat: Hat 'green hat' 'green hat' @startRoom;
redHat: Hat 'red hat' 'red hat' @startRoom;

modify Actor
curHat {
for(local cur = firstObj(Hat); cur != nil;
cur = nextObj(cur, Hat)) {
if (cur.isWornBy(self))
return cur;
}
return nil;
}
;

notWearingHat: PreCondition
checkPreCondition(obj, allowImplicit) {
// if gActor is already not wearing a hat, we're already done
if (gActor.curHat == nil)
return nil;
// try to implicitly remove the hat
if (allowImplicit && tryImplicitAction(Doff, gActor.curHat)) {
// We just tried the implicit command. If it didn't work,
// abort.
if (gActor.curHat != nil)
exit;
// tell the caller we executed an implied command
return true;
}
// can't remove the hat implicitly; report the failure
conditionFailed(obj);
exit;
}
// The condition failed; report the failure and give up.
conditionFailed(obj) {
// can't open it implicitly - report failure and give up
reportFailure('{You/he} {can\'t} do that because {you\'re}
wearing a hat already. ');
// make it the pronoun
gActor.setPronounObj(obj);
}
;

HappyEngineer

unread,
Aug 15, 2006, 1:58:59 AM8/15/06
to

That works perfectly! Thanks!

0 new messages