trigger issues

Posted by Silencher on Fri 23 Jan 2015 02:35 AM — 5 posts, 23,054 views.

#0
It's been a while since I've used mushclient/lua and I can't remember how to do this anymore.

I'm trying to count the number of items I have in a certain line.

Here's an example of raw-output:

In the leather utility belt you see some average ground arnica (x31), some average ground yora root (x10), some potent ground yora root (x2), some average ground stems of thistleweed (x5) and some potent ground stems of thistleweed.

What I'm trying to do is make triggers for each 'type' of herb that will count the numeric value. My trigger right now is:

.*some average ground stems of thistleweed \(x*\).*

with the body containing:

averagethistleweed = %2
Note (averagethistleweed)

But it doesn't seem to be working. What I was then going to do was have an alias list all these items, but that's a separate issue and one I know how to do. I just can't seem to catch that '5' in the 'average ground stems of thistleweed (x5)' line.

I also have the 'keep evaluating, enabled, and regular expression' boxes checked on the right hand side.

If I can get help with this that would be great.
Australia Forum Administrator #1
Can you post the actual trigger please?

Template:copying
For advice on how to copy aliases, timers or triggers from within MUSHclient, and paste them into a forum message, please see Copying XML.
#2
<triggers>
<trigger
enabled="y"
group="herbcount"
keep_evaluating="y"
match=".*some average ground stems of thistleweed \(x*\).*"
regexp="y"
send_to="12"
sequence="100"
>
<send>averagethistleweed = %2
Note (averagethistleweed)</send>
</trigger>
</triggers>
USA #3
For one, one of the issues is the trigger is not actually firing. You have nothing in the trigger that captures the actual number. Im assuming you meant to do x.*. Its better and faster to use x/d. /d starts for 0-9.

Try this. You can actually name your wildcards with (?P<name>pattern)

its best if you paste this into mushclient before you try to read it, Pasting this script on the forum changes certain things because of forums code. So it doesnt look exactly right on here, but it will paste correctly into mushclient and show correctly there.

Talks about why things look different on here compared to on the client.
http://mushclient.com/forum/?id=4776&reply=3#reply3


<triggers>
  <trigger
   enabled="y"
   expand_variables="y"
   group="herbcount"
   keep_evaluating="y"
   match="^some average ground stems of thistleweed \(x(?P&lt;ammount&gt;.*)\)"
   regexp="y"
   send_to="12"
   sequence="100"
  >
  <send>print(%&lt;ammount&gt;)</send>
  </trigger>
</triggers>



Also I love this website below if I cant figure out why my regexp trigger is not firing. Note this website doesnt work for lua regexp, but works for the standard regexp used in triggers and alias.

https://www.regex101.com/
Amended on Fri 23 Jan 2015 06:38 PM by Slick2175
Australia Forum Administrator #4
There are two sorts of regexp, one is the PCRE one used in triggers and aliases (Perl-Compatible) and the other one is the Lua one used in string.find, string.match etc.

Template:regexp
Regular expressions
  • Regular expressions (as used in triggers and aliases) are documented on the Regular expression tips forum page.
  • Also see how Lua string matching patterns work, as documented on the Lua string.find page.


Post an example of what is not working, and what you are trying to match on.