[Home] [Downloads] [Search] [Help/forum]


Register forum user name Search FAQ

Gammon Forum

[Folder]  Entire forum
-> [Folder]  MUSHclient
. -> [Folder]  General
. . -> [Subject]  Bracket capture for triggers

Bracket capture for triggers

You need to log onto the forum to reply or create new threads.

  [Refresh] Refresh page


Posted by Xandler   (52 posts)  [Biography] bio
Date Tue 02 Jul 2024 06:51 PM (UTC)
Message
Sorry if this was posted somewhere else and I didn't see it, I've been browsing the forums looking for similar but couldn't find any applicable. Long story short, I play on a mud that sometimes has brackets ([]) around the text and I'm trying to capture that text and send it to a variable to add it up ie [Double Points] You have gained x [*clan] clan points for doing y.

What I currently have is:

<triggers>
  <trigger
   enabled="y"
   group="CP_Count"
   match="^([Double Clan Points] )?(\w+) (have|has) earned (\d+) [\*clan] clan point from (your|their) valiant effort in slaying (.+)!?"
   regexp="y"
   send_to="12"
   sequence="100"
  >
  <send>CP = tonumber (GetVariable ("CP")) or 0
CP = CP + %3
SetVariable ("CP", CP)</send>
  </trigger>
</triggers>

Do note that this match was given to me by someone using a different client (that uses LUA) but it's still LUA based
I've been testing that with the manual test trigger function in mushclient and it just stays at 0 matches, I'm at a loss on how to make it work. Is there anything simple I'm just not seeing?
[Go to top] top

Posted by Nick Gammon   Australia  (23,016 posts)  [Biography] bio   Forum Administrator
Date Reply #1 on Tue 02 Jul 2024 08:44 PM (UTC)

Amended on Tue 02 Jul 2024 08:45 PM (UTC) by Nick Gammon

Message
To match round or square brackets in a regular expression, just put a backslash in front of it, so for example \[foo\] would match [foo].

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Xandler   (52 posts)  [Biography] bio
Date Reply #2 on Wed 03 Jul 2024 02:14 AM (UTC)

Amended on Wed 03 Jul 2024 02:16 AM (UTC) by Xandler

Message
Nick Gammon said:

To match round or square brackets in a regular expression, just put a backslash in front of it, so for example \[foo\] would match [foo].


So, in theory it should be

^\[Double Clan Points\] (.*?) (has|have) earned (.*?) \[\*clan\] clan (.*?) from (your|their) valiant effort in slaying (.*?)!$


But that isn't matching either?
[Go to top] top

Posted by Nick Gammon   Australia  (23,016 posts)  [Biography] bio   Forum Administrator
Date Reply #3 on Wed 03 Jul 2024 07:06 AM (UTC)
Message

 ie [Double Points] You have gained x [*clan] clan points for doing y.


OK, you need to show exactly what arrives from the MUD.


Your trigger was "[Double Clan Points]" so that is not the same as [Double Points] is it?

Then you say "for doing y" which is not the same as "from (your|their) valiant effort in slaying" is it?

You may be paraphrasing, but in order to help we need to see the exact message coming from the MUD.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Xandler   (52 posts)  [Biography] bio
Date Reply #4 on Wed 03 Jul 2024 08:24 PM (UTC)

Amended on Thu 04 Jul 2024 01:58 AM (UTC) by Xandler

Message
Nick Gammon said:


 ie [Double Points] You have gained x [*clan] clan points for doing y.


OK, you need to show exactly what arrives from the MUD.


Your trigger was "[Double Clan Points]" so that is not the same as [Double Points] is it?

Then you say "for doing y" which is not the same as "from (your|their) valiant effort in slaying" is it?

You may be paraphrasing, but in order to help we need to see the exact message coming from the MUD.


The exact match is:

^\[Double Clan Points\] (.*?) (has|have) earned (.*?) \[\*SDS\] clan (.*?) from (your|their) valiant effort in slaying (.*?)!$


I've tried numerous times "testing" it with the test trigger for mushclient and unable to get it to have a match.
[Go to top] top

Posted by Nick Gammon   Australia  (23,016 posts)  [Biography] bio   Forum Administrator
Date Reply #5 on Wed 03 Jul 2024 11:56 PM (UTC)
Message
OK, that's the trigger. Now post the message from the MUD that it is supposed to match, but is not matching.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Xandler   (52 posts)  [Biography] bio
Date Reply #6 on Thu 04 Jul 2024 02:03 AM (UTC)
Message

[Double Clan Points] You have earned 2 [*SDS] clan point from your valiant effort in slaying Lootie the Living Loot Box!

Supposed to match that (for example) but with You, the actual number, point, your, and the *mob name* substituted out like in the trigger, if that makes sense.
[Go to top] top

Posted by Fiendish   USA  (2,525 posts)  [Biography] bio   Global Moderator
Date Reply #7 on Thu 04 Jul 2024 04:55 PM (UTC)

Amended on Thu 04 Jul 2024 05:42 PM (UTC) by Fiendish

Message
The regular expression
^\[Double Clan Points\] (.*?) (has|have) earned (.*?) \[\*SDS\] clan (.*?) from (your|their) valiant effort in slaying (.*?)!$

does match the line
Quote:
[Double Clan Points] You have earned 2 [*SDS] clan point from your valiant effort in slaying Lootie the Living Loot Box!


I tested it, and sending print("%1", "%2", "%3", "%4", "%5", "%6") did the right thing.

https://github.com/fiendish/aardwolfclientpackage
[Go to top] top

Posted by Xandler   (52 posts)  [Biography] bio
Date Reply #8 on Thu 04 Jul 2024 08:52 PM (UTC)
Message
Fiendish said:

The regular expression
^\[Double Clan Points\] (.*?) (has|have) earned (.*?) \[\*SDS\] clan (.*?) from (your|their) valiant effort in slaying (.*?)!$

does match the line
Quote:
[Double Clan Points] You have earned 2 [*SDS] clan point from your valiant effort in slaying Lootie the Living Loot Box!


I tested it, and sending print("%1", "%2", "%3", "%4", "%5", "%6") did the right thing.


That is really strange because I can't get it to "match" on the mud at all but this will match:


<triggers>
  <trigger
   enabled="y"
   group="CP_Count"
   match="^(\[Double Clan Points\] )?(\w+) (have|has) earned (\d+) [\*SDS] clan point from (your|their) valiant effort in slaying (.+)!?"
   regexp="y"
   send_to="12"
   sequence="100"
  >
  <send>CP = tonumber (GetVariable ("CP")) or 0
CP = CP + %4
SetVariable ("CP", CP)</send>
  </trigger>
</triggers>
[Go to top] top

Posted by Nick Gammon   Australia  (23,016 posts)  [Biography] bio   Forum Administrator
Date Reply #9 on Thu 04 Jul 2024 11:19 PM (UTC)
Message
You omitted the final $ from the regular expression so maybe there is a space at the end of the line from the MUD.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] 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.


465 views.

You need to log onto the forum to reply or create new threads.

  [Refresh] Refresh page

Go to topic:           Search the forum


[Go to top] top

Quick links: MUSHclient. MUSHclient help. Forum shortcuts. Posting templates. Lua modules. Lua documentation.

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

[Home]


Written by Nick Gammon - 5K   profile for Nick Gammon on Stack Exchange, a network of free, community-driven Q&A sites   Marriage equality

Comments to: Gammon Software support
[RH click to get RSS URL] Forum RSS feed ( https://gammon.com.au/rss/forum.xml )

[Best viewed with any browser - 2K]    [Hosted at HostDash]