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 ➜ trigger matched group nil if matched content is string

trigger matched group nil if matched content is string

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

  Refresh page


Posted by Renegadesofcrunk   (2 posts)  Bio
Date Fri 13 Sep 2024 07:17 PM (UTC)

Amended on Sat 14 Sep 2024 01:34 AM (UTC) by Nick Gammon

Message
First off thank you Mr Gammon for all your contributions to this space. I'm really enjoying applying my chosen career's computer science skills to telnet text based DnD gaming from my childhood in the 90s.

I have a working prompt trigger which can capture any numeric value from my prompt, but returns nil for any matched segment that is a string instead of a number.

Trigger:


<triggers>
  <trigger
   enabled="y"
   expand_variables="y"
   group="prompt"
   ignore_case="y"
   match="^\&lt;\{(.*?)\} \[(.*)\] \[(.*?)\/(.*?)hp (.*?)\/(.*?)m (.*?)\/(.*?)mv\]\&gt;(.*)$"
   name="prompt"
   regexp="y"
   send_to="12"
   sequence="100"
  >
  <send>if %1 == 1 then
  Fighting = 1
  TargetHealth = %2
  curHP = %3
  maxHP = %4
  curM = %5
  maxM = %6
  curMV = %7
  maxMV = %8
  Note ("mob condition:")
  Note (%2)
elseif %1 == 0 then
  Fighting = 0
  TargetHealth = "NA"
  curXP = %2
  curHP = %3
  maxHP = %4
  curM = %5
  maxM = %6
  curMV = %7
  maxMV = %8
end -- if

</send>
  </trigger>
</triggers>


example prompt values that the MUD displays which fire my trigger.

when fighting ("cprompt"):


<{1} [Injured] [103132/100085hp 98005/98005m 99805/99805mv]>


when not fighting (normal "prompt")


<{0} [1165429] [102779/100085hp 98005/98005m 99805/99805mv]>


%1 and %3-8 work great and return the expected numbers when I output them with Note().

%2 is always nil when in combat, and properly shows the numeric exp value when not in combat

I originally was using "WAR" and "Peace" instead of 1 and 0 for the %1 value in my prompt and cprompt definitions, but they were also always nil until I changed them to numeric. I can't changed the target enemy condition format to a numeric value because that's not an option the MUD offers. How can I tweak trigger definition to capture strings?

Note this behavior was the same before I converted it to regex, when using * * */* */* */* syntax. I just thought full regex might fix it. It doesn't work any worse as regex though.

Further, pasting my exact regex and example prompt strings into https://regex101.com/ result in proper matching of the second group (the string). I'm sure it's some difference between regex version/support that I can't seem to glean from reading others posts and the docs.

Thank you in advance for reading my wall-o-text!

-Crunk
Top

Posted by Nick Gammon   Australia  (23,070 posts)  Bio   Forum Administrator
Date Reply #1 on Sat 14 Sep 2024 01:36 AM (UTC)
Message
For strings, you need to quote the wildcard.

ie. Instead of:


  TargetHealth = %2


Use:


  TargetHealth = "%2"

- Nick Gammon

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

Posted by Renegadesofcrunk   (2 posts)  Bio
Date Reply #2 on Sat 14 Sep 2024 01:44 AM (UTC)
Message
You are the man Nick. Works perfectly.

Thank You!
Top

Posted by Nick Gammon   Australia  (23,070 posts)  Bio   Forum Administrator
Date Reply #3 on Sat 14 Sep 2024 01:50 AM (UTC)
Message
Quote:

I originally was using "WAR" and "Peace" instead of 1 and 0 for the %1 value in my prompt and cprompt definitions, but they were also always nil until I changed them to numeric. I can't changed the target enemy condition format to a numeric value because that's not an option the MUD offers. How can I tweak trigger definition to capture strings?


Same applies to %1.

- 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.


348 views.

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

  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.