intfiction.org

The Interactive Fiction Community Forum
It is currently Mon Nov 12, 2018 4:07 pm

All times are UTC - 6 hours [ DST ]




Post new topic Reply to topic  [ 3 posts ] 
Author Message
PostPosted: Tue Jul 31, 2018 4:14 pm 
Offline

Joined: Wed Jul 25, 2018 8:55 am
Posts: 18
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:

Code:
DefineTAction(Purchase);
VerbRule(Purchase) ('purchase' | 'buy') dobjList : PurchaseAction
    verbPhrase = 'purchase/purchasing (what)'
;

modify Thing
    dobjFor(Purchase){
        verify(){ illogical('{You/he} can\'t purchase that. '); }
    }
;

class Purchasable: Thing
    isPurchased = nil
    dobjFor(Purchase){
        preCond = [objHeld]
        verify(){}
        action(){
            "{You/he} purchase{s} <<theName>>. ";
            moveInto(gActor);
            isPurchased = true;
        }
    }
;


I'd like to use 'purchase' or 'buy' based on how the player typed in the command. E.g.,

> Buy toy

You buy the toy

> Purchase painting

> You purchase the painting.

Can I do this? Should I even bother?

Thanks


Top
 Profile Send private message  
Reply with quote  
PostPosted: Tue Jul 31, 2018 6:10 pm 
Offline
User avatar

Joined: Tue Apr 20, 2010 2:48 pm
Posts: 1033
Location: Greece
I wouldn't bother, but if you still want to do it, you can either fake it by examining the actual text:

Code:
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:

Code:
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.)

_________________
@realnc


Top
 Profile Send private message  
Reply with quote  
PostPosted: Wed Aug 01, 2018 3:23 pm 
Offline

Joined: Wed Jul 25, 2018 8:55 am
Posts: 18
Thanks.


Top
 Profile Send private message  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC - 6 hours [ DST ]


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group