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 ➜ General ➜ Sound Trigger Exclusion

Sound Trigger Exclusion

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

  Refresh page


Posted by Dukeskath   (11 posts)  Bio
Date Sat 10 Aug 2024 11:24 AM (UTC)

Amended on Sat 10 Aug 2024 11:28 AM (UTC) by Dukeskath

Message
I'm having trouble reproducing something I've already solved.

I made a trigger to play a punching sound every time my attack does NOT miss. It works perfectly:

Quote:

<triggers>
<trigger
enabled="y"
ignore_case="y"
keep_evaluating="y"
match="Your acidic bite* (?!misses)"
regexp="y"
send_to="12"
sequence="100"
>
<send>PlaySound(0, "C:/Users/scart/OneDrive/Documents/MUDs/MUD Sounds/punch.wav", false)
</send>
</trigger>
</triggers>


So now I want to make a trigger to play one sound every time I eat something OTHER than a pill. (Identified on the server with a [pill] tag in brackets.) Here's the code I've got, which feels very similar to the above:

Quote:

<triggers>
<trigger
custom_colour="5"
enabled="y"
ignore_case="y"
keep_evaluating="y"
match="You eat* (?!pill)"
regexp="y"
send_to="12"
sequence="100"
>
<send>PlaySound(0, "C:/Yorda Misc/MUDs/mud sounds x/eating_simp.wav", false)
</send>
</trigger>
</triggers>


When I eat a pill, this eating sound still plays. What am I doing wrong?
Top

Posted by Nick Gammon   Australia  (23,057 posts)  Bio   Forum Administrator
Date Reply #1 on Sat 10 Aug 2024 08:54 PM (UTC)

Amended on Sat 10 Aug 2024 08:56 PM (UTC) by Nick Gammon

Message
The simple solution would be to just test if the wildcard had the word pill in it, in the trigger, eg.


<triggers>
  <trigger
   custom_colour="5"
   enabled="y"
   ignore_case="y"
   keep_evaluating="y"
   match="You eat *"
   send_to="12"
   sequence="100"
  >
  <send>

if not string.match ("%1", "pill") then
  PlaySound(0, "C:/Yorda Misc/MUDs/mud sounds x/eating_simp.wav", false)
end -- if</send>

  </trigger>
</triggers>


In the above example I made the match text not a regular expression.





To solve it with a regular expression you need to be aware that "You eat*" does not match "You eat" followed by anything, it matches "You ea" followed by zero or more of the letter "t", eg. "You ea", "You eat", "You eatt", "You eattt" and so on.

So at the very least you need ".*" to match "zero or more of anything".



<triggers>
  <trigger
   custom_colour="5"
   enabled="y"
   ignore_case="y"
   keep_evaluating="y"
   match="You eat (?!.*\bpill\b).*"
   regexp="y"
   send_to="12"
   sequence="100"
  >
  <send>PlaySound(0, "C:/Yorda Misc/MUDs/mud sounds x/eating_simp.wav", false)
</send>
  </trigger>
</triggers>


What I have done above is put the ".*" inside the brackets, so that the negative look-ahead assertion includes any intervening words. Also be aware that when using regular expressions if the matching text is supposed to be at the start of the line you should put "^" in front of it, eg.


   match="^You eat (?!.*\bpill\b).*"


The \b is for a word boundary, so it matches on "pill" but not "pillion" or "pillock".

- Nick Gammon

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

Posted by Dukeskath   (11 posts)  Bio
Date Reply #2 on Sat 10 Aug 2024 09:39 PM (UTC)
Message
Thank you so much, Nick. I appreciate your willingness to provide solutions AND explain how the process works. I've been teaching HS English for 24 years and I cannot tell you how many programmers are unwilling to help new folks wrap their brains around the process as well as the code. So I thank you for that.

I'll tinker with what you've posted and hopefully my silly desire to tweak every moment of the game will soon be perfect. THEN I'll be happy! :)
Top

Posted by Dukeskath   (11 posts)  Bio
Date Reply #3 on Sat 10 Aug 2024 10:39 PM (UTC)
Message
For some reason the first bit you posted did not work. But the second one (regex) did. Thank you!
Top

Posted by Nick Gammon   Australia  (23,057 posts)  Bio   Forum Administrator
Date Reply #4 on Sun 11 Aug 2024 07:56 PM (UTC)
Message
You needed to uncheck "regular expression". I tested it and it worked for me.

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


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