TinTin++ Mud Client The TinTin++ message board

 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
TinTin++ Mud Client

splitting a sentence

 
Post new topic   Reply to topic    The TinTin++ message board Forum Index -> General Discussion
View previous topic :: View next topic  
Author Message
gulca



Joined: 11 May 2011
Posts: 5

PostPosted: Wed May 11, 2011 5:33 pm    Post subject: splitting a sentence Reply with quote

I'm trying to write a trigger to sell a bunch of stuff with various names. These names might be single words, 2 words, 5 words etc. Not all words are keywords, but the last word is probably the right keyword 95% of the time.

I want to use this last word to trigger and autosell when I get all the stuff from a container

For example,
You get a small axe from a bag.
You get a wonderful yellow minted head from a bag.
You get a die from a bag.


The following don't work.
Code:

#action {You get %1 from a bag.} {sell %1}

It will try to sell small (ok), sell wonderful (not ok), sell die (ok).

I would want to split the %1 into a list, and use the last member of that list to sell.

So, I would get
axe, head, die as my final results.

Thanks.
Back to top
View user's profile Send private message
Scandum
Site Admin


Joined: 03 Dec 2004
Posts: 3274

PostPosted: Wed May 11, 2011 6:47 pm    Post subject: Reply with quote

Try:

Code:

#action {You get %1 from a bag.} {sell %1}
{
    #regex {{.*} %*}
    {
        sell &2
    }
}


{.*} forces a greedy match, as %* is lazy by default. See #help regex for more info.
Back to top
View user's profile Send private message Send e-mail
gulca



Joined: 11 May 2011
Posts: 5

PostPosted: Thu May 12, 2011 1:48 pm    Post subject: Reply with quote

Thanks for the quick reply Smile
A question on the code Scandum.

Why is the regex on the priority section of the #action command?

I copied and pasted the code and it doesn't work as is.

Nevermind, I got it to work.

Code:

#action {You get %1 from a bag.}
{ #regex {%1} {{.*} %*} {#sell &2}}


Thanks again. This makes looting and selling stuff for coins easy.
Back to top
View user's profile Send private message
Chicomecoatl



Joined: 08 Sep 2009
Posts: 73
Location: Kansas

PostPosted: Thu May 12, 2011 2:40 pm    Post subject: Reply with quote

Another alternative is direct action regexp integration (my preferred method). If you put curly braces inside the action, you can embed regexp.

for example:

Code:


#act {^You get {.* (\S+)} from a bag.$}
{
     sell %2
}


_________________
Chico
Back to top
View user's profile Send private message Send e-mail Visit poster's website Yahoo Messenger MSN Messenger
Display posts from previous:   
Post new topic   Reply to topic    The TinTin++ message board Forum Index -> General Discussion All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
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 vote in polls in this forum
Get TinTin++ Mud Client at SourceForge.net. Fast, secure and Free Open Source software downloads Get TinTin++ Mud Client at SourceForge.net. Fast, secure and Free Open Source software downloads
TinTin++ Homepage

Powered by phpBB © 2001, 2002 phpBB Group