[Home] [Downloads] [Search] [Help/forum]

Gammon Software Solutions forum

See www.mushclient.com/spam for dealing with forum spam. Please read the MUSHclient FAQ!

[Folder]  Entire forum
-> [Folder]  MUSHclient
. -> [Folder]  General
. . -> [Subject]  regexp variable extracting (?)
Home  |  Users  |  Search  |  FAQ
Username:
Register forum user name
Password:
Forgotten password?

regexp variable extracting (?)

It is now over 60 days since the last post. This thread is closed.   [New subject]  Start a new subject   [Refresh] Refresh page


Posted by Doorie   Finland  (10 posts)  [Biography] bio
Date Wed 07 Mar 2012 01:22 PM (UTC)  quote  ]
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

[Go to top] top

Posted by Nick Gammon   Australia  (19,531 posts)  [Biography] bio   Forum Administrator
Date Reply #1 on Thu 08 Mar 2012 04:19 AM (UTC)  quote  ]

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
[Go to top] top

Posted by Doorie   Finland  (10 posts)  [Biography] bio
Date Reply #2 on Thu 08 Mar 2012 05:07 PM (UTC)  quote  ]

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!)
[Go to top] top

Posted by Nick Gammon   Australia  (19,531 posts)  [Biography] bio   Forum Administrator
Date Reply #3 on Thu 08 Mar 2012 06:57 PM (UTC)  quote  ]
Message
There's another video about variables ;)

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

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Doorie   Finland  (10 posts)  [Biography] bio
Date Reply #4 on Thu 08 Mar 2012 07:14 PM (UTC)  quote  ]
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.
[Go to top] top

Posted by Nick Gammon   Australia  (19,531 posts)  [Biography] bio   Forum Administrator
Date Reply #5 on Thu 08 Mar 2012 10:25 PM (UTC)  quote  ]
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
[Go to top] top

Posted by Doorie   Finland  (10 posts)  [Biography] bio
Date Reply #6 on Fri 09 Mar 2012 05:55 PM (UTC)  quote  ]
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.
[Go to top] 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.


1,616 views.

It is now over 60 days since the last post. This thread is closed.   [New subject]  Start a new subject   [Refresh] Refresh page

Go to topic:           Search the forum


[Go to top] top

Quick links: MUSHclient. MUSHclient help. Forum shortcuts. Posting templates. Lua modules. Lua documentation.

[Home]

Written by Nick Gammon - 5K

Comments to: Gammon Software support
[RH click to get RSS URL] Forum RSS feed ( http://www.gammon.com.au/rss/forum.xml )

[Best viewed with any browser - 2K]    [Web site powered by FutureQuest.Net]