[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]  Editing a table with wildcards
Home  |  Users  |  Search  |  FAQ
Register forum user name
Forgotten password?

Editing a table with wildcards

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

Posted by Serris   (12 posts)  [Biography] bio
Date Sun 13 Feb 2011 09:55 AM (UTC)
I am making a limb counter for Achaea and I have a bunch of functions but one of them I need help with. To start, it uses this table:

bodypart = {
  head = 0,
  torso = 0,
  rightarm = 0,
  leftarm = 0,
  rightleg = 0,
  leftleg = 0,

The function looks like this:

function limbhit(sTrig, sLine, wildcs) -- adds damage to limbs. 1 for punch, 2 for kick

  bodypart.wildcs[1] = (bodypart.wildcs[1] or 0) + 1
  if GetVariable("attack") == "kick" then
    bodypart.wildcs[1] = bodypart.wildcs[1] + 1

end -- function

One of my triggers fires on "^You connect to the (.+)\.$ The (.+) could be head, torso, left leg, right leg, left arm, right arm. Since I cannot have a space between left and arm or left and leg in the table (left leg gives me an error), I need some way of combining those two words. I could do:

bodypart.wildcs[2]wildcs[2] = (bodypart.wildcs[1]wildcs[2] or 0) + 1

but that will only work if there are two wildcards in the trigger, and there isn't always. Is there anyway I could do something with gsub and then edit the table or is there an easier way to take care of this?
[Go to top] top

Posted by Nick Gammon   Australia  (21,607 posts)  [Biography] bio   Forum Administrator
Date Reply #1 on Sun 13 Feb 2011 06:47 PM (UTC)
Doing this:

bodyparts.foot = "foo"

is "syntactic sugar" for:

bodyparts ["foot"] = "foo"

So, extending this, whilst this gives an error:

bodyparts.left leg = "foo"

This won't:

bodyparts ["left leg"] = "foo"

So, just change the way you access the table.

- Nick Gammon

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

Posted by Serris   (12 posts)  [Biography] bio
Date Reply #2 on Mon 14 Feb 2011 11:27 PM (UTC)
Hah, awesome. Thank you much!
[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.


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.


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]