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.

Due to spam on this forum, all posts now need moderator approval.

 Entire forum ➜ MUSHclient ➜ General ➜ Problem with Regexp

Problem with Regexp

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


Posted by Halig   Portugal  (123 posts)  Bio
Date Tue 29 Dec 2015 11:23 PM (UTC)
Message
Hello to you all. It's been a while. I have a new problem that i can't seem to fix.


<triggers>
  <trigger
   enabled="y"
   match="([^.]+)(\s+)([^.]+) Dried fruit rations"
   regexp="y"
   send_to="12"
   sequence="100"
  >
  <send>dried = "%1"

first = string.match(dried, "((%d+))")

SetVariable ("dried", first)

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


The MUD output is:

(71) (Assorted) Dried fruit rations

I'm trying to save to a variable the number of Dried fruit rations that i have on the inventory.

That works, but if i send to the MUD "drop dried" it gives the following error:

[string "Trigger: "]:5: bad argument #2 to 'SetVariable' (string expected, got nil)
stack traceback:
[C]: in function 'SetVariable'
[string "Trigger: "]:5: in main chunk

How can i fix this?

Thank you.
Top

Posted by Nick Gammon   Australia  (23,133 posts)  Bio   Forum Administrator
Date Reply #1 on Wed 30 Dec 2015 05:16 AM (UTC)
Message
Quote:

That works, but if i send to the MUD "drop dried" it gives the following error:


If you send "drop dried" what is the MUD output?

- Nick Gammon

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

Posted by Halig   Portugal  (123 posts)  Bio
Date Reply #2 on Wed 30 Dec 2015 10:01 AM (UTC)
Message
Hi Nick,

The MUD output is:

You release (Assorted) Dried fruit rations from your grasp.
(Assorted) Dried fruit rations hits the ground.
Top

Posted by Halig   Portugal  (123 posts)  Bio
Date Reply #3 on Wed 30 Dec 2015 08:43 PM (UTC)

Amended on Wed 30 Dec 2015 08:44 PM (UTC) by Nick Gammon

Message
I've figured it out.

Made two triggers.


<triggers>
  <trigger
   enabled="y"
   group="Inventory"
   lines_to_match="2"
   match="You are carrying:"
   regexp="y"
   send_to="12"
   sequence="100"
  >
  <send>EnableTrigger ( "inv", true )</send>
  </trigger>
</triggers>


And that one, enables the second one:


<triggers>
  <trigger
   group="Inventory"
   match="^([^.]+)(.*)([^.]+) Dried fruit rations"
   name="inv"
   regexp="y"
   send_to="12"
   sequence="100"
  >
  <send>number = "%1"

first = string.match(number, "((%d+))")

SetVariable ("dried", first)

EnableTrigger ( "inv", false )</send>
  </trigger>
</triggers>


This way all is working like i wanted to.

Thank you.
Top

Posted by Nick Gammon   Australia  (23,133 posts)  Bio   Forum Administrator
Date Reply #4 on Wed 30 Dec 2015 08:46 PM (UTC)
Message
I was about to suggest that:


 (Assorted) Dried fruit rations hits the ground.


That has more words after "Dried fruit rations" so you could have put a "$" at the end of the regexp to make it match that text with nothing after it.

- Nick Gammon

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

Posted by Halig   Portugal  (123 posts)  Bio
Date Reply #5 on Wed 30 Dec 2015 09:05 PM (UTC)
Message
Hi Nick.

At least i learned something.
I've changed the all thing to the $ that you said, at least i don't have too many triggers :).

Thank you.
Top

Posted by Nick Gammon   Australia  (23,133 posts)  Bio   Forum Administrator
Date Reply #6 on Thu 31 Dec 2015 03:43 AM (UTC)
Message
The other thing you can do, since you want to match a number (or it won't work) is to make that explicit. Change:


([^.]+)


at the start of the regexp to:


([0-9]+)


Now that won't match on "You release" so the trigger doesn't fire.

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


16,376 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.