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, confirm your email, resolve issues, 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 ➜ A more complicated trigger than I am used to

A more complicated trigger than I am used to

It is now over 60 days since the last post. This thread is closed.     Refresh page


Posted by Anthonyl   (2 posts)  Bio
Date Mon 30 Oct 2023 01:29 PM (UTC)
Message
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.
Top

Posted by Fiendish   USA  (2,533 posts)  Bio   Global Moderator
Date Reply #1 on Mon 30 Oct 2023 04:04 PM (UTC)

Amended on Mon 30 Oct 2023 04:06 PM (UTC) by Fiendish

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

https://github.com/fiendish/aardwolfclientpackage
Top

Posted by Anthonyl   (2 posts)  Bio
Date Reply #2 on Mon 30 Oct 2023 04:52 PM (UTC)

Amended on Mon 30 Oct 2023 04:53 PM (UTC) by Anthonyl

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


2,986 views.

It is now over 60 days since the last post. This thread is closed.     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.