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
➜ Lua
➜ Editing a table with wildcards
Editing a table with wildcards
|
It is now over 60 days since the last post. This thread is closed.
Refresh page
Posted by
| Serris
(12 posts) Bio
|
Date
| Sun 13 Feb 2011 09:55 AM (UTC) |
Message
| 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
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? | Top |
|
Posted by
| Nick Gammon
Australia (23,133 posts) Bio
Forum Administrator |
Date
| Reply #1 on Sun 13 Feb 2011 06:47 PM (UTC) |
Message
| Doing this:
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 | Top |
|
Posted by
| Serris
(12 posts) Bio
|
Date
| Reply #2 on Mon 14 Feb 2011 11:27 PM (UTC) |
Message
| Hah, awesome. Thank you much! | 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.
10,195 views.
It is now over 60 days since the last post. This thread is closed.
Refresh page
top