A more complicated trigger than I am used to

Posted by Anthonyl on Mon 30 Oct 2023 01:29 PM — 3 posts, 8,910 views.

#0
Hi, I am trying to parse a phrase from the MUD, and not sure how to do it. I wonder if someone could help me come up with the trigger. I am used to basic triggers, so if my client spits out:

"You need to get paint from the shed and give it to Boris by 4pm"

My trigger text is:
You need to get * from the * and give it to * by *


and in my send to script below I use:

  SetVariable ("item", "%1")
  SetVariable ("location", "%2")
  SetVariable ("customer", "%3") 


top set my variables. I ignore the last *, I am not bothered about the time.


I have a more complicated one, and I don't know how to parse it.

My client spits out "I need you to get 4 green flowers and a navy blue jacket from the boat" and I want to store some of it in variables.

Now, I need to get the number of flowers for one variable, the color of the flowers (which may be 1 or 2 words, a hundred different color possibilities exist) for the second variable, the color of the clothing for the 3rd variable (again 1 or 2 words), and the clothing type (will be jacket, shirt, boots, or britches). But because some arguments are next to others, I don't know how to do this. If the arguments were seperated I could do it with my very basic trigger understanding, but I can't figure this one out.

Any help with how to phrase my trigger would be very appreciated.
USA Global Moderator #1
Perhaps something like


<triggers>
  <trigger
   enabled="y"
   match="^I need you to get (\d+) (.+) flowers and a (.+) (jacket|shirt|boots|britches) from the boat"
   regexp="y"
   send_to="12"
   sequence="100"
  >
  <send>print("%1")
print("%2")
print("%3")
print("%4")</send>
  </trigger>
</triggers>




Receiving "I need you to get 4 green flowers and a navy blue jacket from the boat"

prints...

4
green
navy blue
jacket


Template:pasting
For advice on how to copy the above, and paste it into MUSHclient, please see Pasting XML.
Amended on Mon 30 Oct 2023 04:06 PM by Fiendish
#2
Thanks Fiendish. After asking this question, I went away and tried to learn some regex stuff myself, and came up with my own solution.

I used


^I need you to get (?P<number>\d) (?P<maincolor>.*) (?P<type>flowers|plants|bulbs) and (a|an) (?P<othercolor>.*) (?P<clothing>jacket|shirt|pair of boots|pair of britches) from .*$


Sorted it out now, thanks for the awesome program and helpful forum.