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

Gammon Forum

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

[Folder]  Entire forum
-> [Folder]  MUSHclient
. -> [Folder]  Lua
. . -> [Subject]  Need help with Lua pattern matching
Home  |  Users  |  Search  |  FAQ
Username:
Register forum user name
Password:
Forgotten password?

Need help with Lua pattern matching

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


Posted by Larkin   (278 posts)  [Biography] bio
Date Tue 22 Feb 2005 08:21 PM (UTC)
Message
I'm trying to make a pattern to match variations on prompts in Achaea/Lusternia. I've got it matching and even capturing values if I have all of them displayed in my prompt (health, mana, endurance, and willpower), but I want something that matches on other prompt configurations, also. Variations would include:

100h, 100m ex-
100h, 100m, 100e ex-
100h, 100m, 100w ex-
100h, 100m, 100e, 100w ex-

I know how to match them all in a singular regular expression. Since Lua doesn't implement the full syntax, I was wondering if anyone might be able to find a way to match them with Lua's pattern matching method.

Here's what I have so far:


  _,_,health,mana,endurance,willpower,flags = string.find(prompt, "^(%d+)h, (%d+)m, (%d+)e, (%d+)w ([cexkdb@-]+)")
[Go to top] top

Posted by David Haley   USA  (3,881 posts)  [Biography] bio
Date Reply #1 on Tue 22 Feb 2005 08:59 PM (UTC)
Message
I'm not sure if this is the most elegant, but you could check for a non-match (by comparing the first return value to nil) and if the first doesn't match, try the second, then the third, and so forth.

David Haley aka Ksilyan
Head Programmer,
Legends of the Darkstone

http://david.the-haleys.org
[Go to top] top

Posted by Larkin   (278 posts)  [Biography] bio
Date Reply #2 on Thu 24 Feb 2005 03:52 PM (UTC)
Message
Here's basically what I ended up doing. Thanks for the idea!

function OnPluginPartialLine(msg)
  _,_,health,mana,flags = string.find(msg, "^(%d+)h, (%d+)m.* ([cexkdb@]+)\-")
  if health and mana then
    Execute("acp_health " .. health)
    Execute("acp_mana " .. mana)
    _,_,endurance = string.find(msg, ", (%d+)e")
    if endurance then
      Execute("acp_endurance " .. endurance)
    end
    _,_,willpower = string.find(msg, ", (%d+)w")
    if willpower then
      Execute("acp_willpower " .. willpower)
    end
  end
  if flags then
    _,_,cloak,eq,bal,kola,deaf,blind,phase = string.find(flags, "(c?)(e?)(x?)(k?)(d?)(b?)(@?)")
    if eq == "" then
      Execute("acp_balance eq false")
    else
      Execute("acp_balance eq true")
    end
    if bal == "" then
      Execute("acp_balance bal false")
    else
      Execute("acp_balance bal true")
    end
    if cloak == "" then
      Execute("acp_undef cloak")
    else
      Execute("acp_ondef cloak")
    end
    if kola == "" then
      Execute("acp_undef kola")
    else
      Execute("acp_ondef kola")
    end
    if deaf == "" then
      Execute("acp_undef deafness")
    else
      Execute("acp_ondef deafness")
    end
    if blind == "" then
      Execute("acp_undef blindness")
    else
      Execute("acp_ondef blindness")
    end
    if phase == "" then
      Execute("acp_undef phase")
    else
      Execute("acp_ondef phase")
    end
  end
end
[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.


4,146 views.

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

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.

[Home]


Written by Nick Gammon - 5K   profile for Nick Gammon on Stack Exchange, a network of free, community-driven Q&A sites   Marriage equality

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

[Best viewed with any browser - 2K]    [Hosted at FutureQuest]