Register forum user name Search FAQ

Gammon Forum

Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to "verify" your details, making threats, or asking for money, are spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the password reset link.
 Entire forum ➜ MUSHclient ➜ Lua ➜ Trouble with triggers.

Trouble with triggers.

It is now over 60 days since the last post. This thread is closed.     Refresh page


Posted by FishOnSpeed   USA  (31 posts)  Bio
Date Fri 28 Mar 2008 06:16 PM (UTC)
Message
Okay. I have two triggers that are very similar. I don't have them doing anything of any value yet ... but I still need them to work.

Heres the problem.

You get * silver coins and * gold coins from the corpse of *.
You get * gold coins from the corpse of *.

So when I only get gold coins it uses the second trigger but when I get gold and silver it still uses the second trigger and tries to set "12 silver coins and" as the first variable. But I want it to use the first trigger I listed.

Is there any way for me to make the client use the one I want when I want it to?

~FishOnSpeed
Top

Posted by Shaun Biggs   USA  (644 posts)  Bio
Date Reply #1 on Fri 28 Mar 2008 07:40 PM (UTC)
Message
Using the generic * will grab anything, numeric or otherwise into the variable. The simple fix is just to set the silver and gold one to a lower sequence than the gold only one. The lower the sequence value, the earlier the trigger engine will evaluate matching. The more accurate fix is to use regular expressions to grab the data.


"^You get (\d+) silver coins and (\d+) gold coins from the corpse of (.*)\.$"
"^You get (\d+) gold coins from the corpse of (.*)\.$"

It is much easier to fight for one's ideals than to live up to them.
Top

Posted by FishOnSpeed   USA  (31 posts)  Bio
Date Reply #2 on Fri 28 Mar 2008 08:06 PM (UTC)
Message
Alright. But what exactly are the (/d+) and the (.*)\ things? What are they doing? And do I use the same %1 ... %2 .. blah blah things to use numbers later in the trigger?

~FishOnSpeed
Top

Posted by Nick Gammon   Australia  (23,046 posts)  Bio   Forum Administrator
Date Reply #3 on Fri 28 Mar 2008 10:51 PM (UTC)

Amended on Fri 28 Mar 2008 10:56 PM (UTC) by Nick Gammon

Message
Take a look at http://www.mushclient.com/regexp

Also, inside the trigger, once you have checked "regular expression" and click on the "..." box to edit the match text, there is a new button (marked "->") which lets you insert regular expression fields easily.

To get started, take your original trigger, which is:


You get * gold coins from the corpse of *.


Then click on the button "Convert to regular expression". This changes it to:


^You get (.*?) gold coins from the corpse of (.*?)\.$


You can see most is the same, except the wildcards are now: (.*?)

In a regular expression, something inside brackets is a "capture" (what we call a wildcard). So, the first capture becomes %1, the second %2, and so on, just like in a normal trigger.

In fact, internally MUSHclient converts all non-regular expression triggers to regular expressions using exactly that method, so it behaves exactly the same.

The dot character means "match anything", unless escaped by a backslash. So the final dot in your original text needs to be literally a dot, so it is there as: \.

The ^ means "anchor to start of the line", and the $ means "anchor to the end of the line". This stops it matching something like:


John says, "You get 20 gold coins from the corpse of the kobold."


Having got this far, let's see what Shaun Biggs suggested. Taking your converted regular expression:


^You get (.*?) gold coins from the corpse of (.*?)\.$


He suggested making it more specific. The regular expression documentation shows that you can match on digits only by using \d.

Also, the "*" character means "zero or more", but we really expect at least one digit, so "+" is used instead, which means "one or more".

Thus the simple change to:


^You get (\d+) gold coins from the corpse of (.*?)\.$


This makes sure that inside wildcard %1 will only be digits - and therefore the text "12 silver coins and" will not match it.

Another way of doing the same thing is with a character class, like this:


^You get ([0-9]+) gold coins from the corpse of (.*?)\.$


Here you are explicitly saying you only want 0-9 (the square brackets let you designate sets of exact characters or ranges).

You could also limit the number of digits, like this:


^You get ([0-9]{1,4}) gold coins from the corpse of (.*?)\.$


Now we are saying we only want between 1 and 4 digits (so a 5-digit number would not match).

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Shaun Biggs   USA  (644 posts)  Bio
Date Reply #4 on Mon 31 Mar 2008 03:41 PM (UTC)
Message
Here's an odd question, since we are making the regex more complicated... is the gold display separated by commas? having a script pull out the commas after capturing the variable might be useful in that case.

^You get (\d{1,3}(?:\,\d{3})*) gold coins from the corpse of (.*?)\.$

Also "\d" is shorthand for "[0-9]" just to clear up any confusion for people not used to regex

It is much easier to fight for one's ideals than to live up to them.
Top

Posted by FishOnSpeed   USA  (31 posts)  Bio
Date Reply #5 on Mon 31 Mar 2008 04:19 PM (UTC)
Message
No there aren't any commas in it. I posted it exactly as it appears on my screen from the mud. Thanks for the help with that.

But now I'm having another problem.

The triggers work right now but if I check the "omit from output" box the trigger no longer sends the information I want it to.

I don't have it doing anything at the moment really. I just want it to omit the long line sent by the mud and replace it with a Note. But when I omit the text the Note no longer pops up. It only shows the Note when I don't gag the text.

~FishOnSpeed
Top

Posted by Nick Gammon   Australia  (23,046 posts)  Bio   Forum Administrator
Date Reply #6 on Mon 31 Mar 2008 08:42 PM (UTC)
Message
See http://mushclient.com/faq point 51 (recently added).

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).

To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.


21,579 views.

It is now over 60 days since the last post. This thread is closed.     Refresh page

Go to topic:           Search the forum


[Go to top] top

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.