Sound Trigger Exclusion

Posted by Dukeskath on Sat 10 Aug 2024 11:24 AM — 5 posts, 8,390 views.

#0
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?
Amended on Sat 10 Aug 2024 11:28 AM by Dukeskath
Australia Forum Administrator #1
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".
Amended on Sat 10 Aug 2024 08:56 PM by Nick Gammon
#2
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! :)
#3
For some reason the first bit you posted did not work. But the second one (regex) did. Thank you!
Australia Forum Administrator #4
You needed to uncheck "regular expression". I tested it and it worked for me.