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 ➜ regexp variable extracting (?)

regexp variable extracting (?)

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


Posted by Doorie   Finland  (10 posts)  Bio
Date Wed 07 Mar 2012 01:22 PM (UTC)
Message
Trigger:
^((.+?) attacks you\.|(.+?) wakes up and starts hitting you\.)@

I need to assign monster name to a variable, so that i can refer it later, for example targetting the right monster.

After numerous help file/forum/whatnot browsing, testing and thinking, I _still_ fail to do this.

I hope my example is clear and enough for an easy answer, and I am sane enough to understand it :P

Top

Posted by Nick Gammon   Australia  (23,165 posts)  Bio   Forum Administrator
Date Reply #1 on Thu 08 Mar 2012 04:19 AM (UTC)

Amended on Thu 08 Mar 2012 04:20 AM (UTC) by Nick Gammon

Message
Well in your case the monster name will be %1 (or maybe %2 because you have a bracket inside a bracket) inside the "send" box.

Perhaps watch this?

http://www.gammon.com.au/forum/?id=9616

- Nick Gammon

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

Posted by Doorie   Finland  (10 posts)  Bio
Date Reply #2 on Thu 08 Mar 2012 05:07 PM (UTC)

Amended on Thu 08 Mar 2012 05:11 PM (UTC) by Doorie

Message

<triggers>
  <trigger
   custom_colour="16"
   enabled="y"
   group="ZZZ TEST General Moving"
   match="^((.+?) leaves (.+)\.|(.+?) arrives (.+)\.|(.+?) gallops (.+)\.|(.+?) slithers (.+)\.|(.+?) rides (.+)\.)$"
   regexp="y"
   send_to="12"
   sequence="100"
  >
  <send>print(" parameters:==&gt; 0:","%0","1:","%1","2:","%2","3:","%3","4:","%4","5:","%5","6:","%6","7:","%7","8:","%8","9:","%9")</send>
  </trigger>
</triggers>


This example seems to put those player (or mob) names who _leaves_, to %2 and their direction to %3.
And those who _arrive_, names to %4 and direction to %5. And so forth...

What i need is to capture player (or mob) names to some variable what i can use later, say, targetting or telling.

How do i do that? Do I have to use GetWildcards, SetVariable, GetVariable or some other funcion? And is there a better ie. shorter way to write that <send>print(".....") part?

(Video was great, i learned few tricks to be used later, thank you for that!)
Top

Posted by Nick Gammon   Australia  (23,165 posts)  Bio   Forum Administrator
Date Reply #3 on Thu 08 Mar 2012 06:57 PM (UTC)
Message
There's another video about variables ;)

http://www.gammon.com.au/forum/?id=10863

- Nick Gammon

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

Posted by Doorie   Finland  (10 posts)  Bio
Date Reply #4 on Thu 08 Mar 2012 07:14 PM (UTC)
Message
But what about inside regular expressions? How do i set some named variable (like: mobname) when i have several choices in the trigger, like:

^((.+?) hits you\.|(.+?) kicks you\.)$


What i noticed from my last message was that if the first one fires (activates) it falls into parameter %1, but the second one goes into parameter %2.

I need to grab the name of a mob that automagically attacks me when i arrive at the room. If I have only one type of information, say : "Snake attacks you!" then it is easy, it's always %1, but when there are more than one automatick attack message, then the next (.+?) goes into %2, third (.+?) to %3 and so on.
Top

Posted by Nick Gammon   Australia  (23,165 posts)  Bio   Forum Administrator
Date Reply #5 on Thu 08 Mar 2012 10:25 PM (UTC)
Message
Oh, right. Well you can use named captures, and use the (?J) option to allow duplicate names.

Then the capture is called "mob" and you can extract that as shown.


<triggers>
  <trigger
   enabled="y"
   match="(?J)^((?P&lt;mob&gt;.+?) hits you\.|(?P&lt;mob&gt;.+?) kicks you\.)$"
   regexp="y"
   send_to="12"
   sequence="100"
  >
  <send>
mobname = "%&lt;mob&gt;"

print ("mobname = ", mobname)
</send>
  </trigger>
</triggers>


Template:pasting For advice on how to copy the above, and paste it into MUSHclient, please see Pasting XML.


The regexp part looks like this without the XML escaping:


(?J)^((?P<mob>.+?) hits you\.|(?P<mob>.+?) kicks you\.)$


- Nick Gammon

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

Posted by Doorie   Finland  (10 posts)  Bio
Date Reply #6 on Fri 09 Mar 2012 05:55 PM (UTC)
Message
Thank You!

That did the trick.
Now I can combine many triggers via regexping and reduce the total amount of triggers.

There are so many functions and different syntaxes that sometimes I get confused. I will code on... step by step.
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.


23,154 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.