I am working on creating a ‘purchase’ verb and I’d like to modify the response based on player input. Here is my code. I’m not wedded to this because I’m not even sure this is the right approach I need to use for what I’m trying to accomplish. Still, the concept I’m going after seem generic enough to ask for clarification:
I wouldn’t bother, but if you still want to do it, you can either fake it by examining the actual text:
DefineTAction(Purchase)
responseText = nil
execAction()
{
// Important: When setting responseText, we need to set it directly on the
// BuyAction class, not on 'self', since 'self' will be a temporary throw-away
// object the adv3 library creates.
//
// Also, when doing these kinds of getOrigText() checks, we need to convert
// to lower case, because the player might have entered the command in
// upper case.
if (gAction.getOrigText().toLower().startsWith('buy ')) {
BuyAction.responseText = 'buy';
} else {
BuyAction.responseText = 'purchase';
}
inherited();
}
;
modify Thing
dobjFor(Purchase){
verify(){ illogical('{You/he} can\'t <<BuyAction.responseText>> that. '); }
}
;
class Purchasable: Thing
isPurchased = nil
dobjFor(Purchase){
preCond = [objHeld]
verify(){}
action(){
"{You/he} <<BuyAction.responseText>>{s} <<theName>>. ";
moveInto(gActor);
isPurchased = true;
}
}
;
It’s a bit hacky, but it should work. If you want a more correct implementation, which would also take care of using correct implicit action text (like “first trying to buy/purchase the thing”) you would need to define two different verbs, one for “buy” and one for “purchase”, but have one of them inherit from the other, and then make sure to get the correct verb form when printing:
DefineTAction(Purchase);
VerbRule(Purchase)
'purchase' singleDobj
: PurchaseAction
verbPhrase = 'purchase/purchasing (what)'
;
DefineAction(Buy, PurchaseAction);
VerbRule(Buy)
'buy' singleDobj
: BuyAction
verbPhrase = 'buy/buying (what)'
;
modify Thing
// This handler will be called for both PurchaseAction as well as BuyAction, since
// BuyAction inherits from PurchaseAction.
dobjFor(Purchase) {
verify()
{
illogical('{You/he} can\'t <<gAction.getVerbPhrase1(true, gAction.verbPhrase, theName, nil)>>. ');
}
}
;
class Purchasable: Thing
isPurchased = nil
dobjFor(Purchase){
preCond = [objHeld]
verify(){}
action(){
"{You/he} <<gAction.getInfPhrase()>>. ";
moveInto(gActor);
isPurchased = true;
}
}
;
But again, there’s no reason to do any of this. “Buy” is just a synonym for “purchase”, just like “take” is a synonym for “pick up”, “look at” is a synonym for “examine”, etc, etc, etc. There’s no reason to treat buy/purchase in a special way. One would then wonder why you did this for buy/purchase, but not for the other actions (and there’s dozens of them.)