| View previous topic :: View next topic |
| Author |
Message |
gulca
Joined: 11 May 2011 Posts: 5
|
Posted: Wed May 11, 2011 5:33 pm Post subject: splitting a sentence |
|
|
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 |
|
 |
Scandum Site Admin
Joined: 03 Dec 2004 Posts: 3274
|
Posted: Wed May 11, 2011 6:47 pm Post subject: |
|
|
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 |
|
 |
gulca
Joined: 11 May 2011 Posts: 5
|
Posted: Thu May 12, 2011 1:48 pm Post subject: |
|
|
Thanks for the quick reply
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 |
|
 |
Chicomecoatl
Joined: 08 Sep 2009 Posts: 73 Location: Kansas
|
Posted: Thu May 12, 2011 2:40 pm Post subject: |
|
|
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 |
|
 |
|