Posted by
| Nick Gammon
Australia (22,975 posts) bio
Forum Administrator |
Message
| You have tables within tables here, so you need to go down a level or two.
To reproduce your test data I made this table:
equipinform = {
["468263929"] = {
level=1,
weight=1,
wearloc="sleeping",
details_captured=true,
stats = {},
owner="Strazor",
objectid="12569898",
flags="glow, hum, magic, held, nopurge, burn-proof, nolocate, solidified, resonated, illuminated, v3, precious",
itemtype="Furniture",
container_id="worn",
resists = {},
name="V3 Trivia Sleeping Bag",
score="0",
},
["965742031"] = {
level=41,
weight=0,
wearloc="neck",
details_captured=true,
stats = {
damageroll=29,
luck=2,
moves=-30,
wisdom=2,
intelligence=2,
hitroll=1,
hitpoints=25,
},
owner="",
objectid="125689755",
flags="unique, glow, hum, magic, held, burn-proof, solidified, illuminated, v3, searchable",
itemtype="Armor",
container_id="worn",
resists = {},
name="(>Asura's Azurite Pearl<)",
score="205",
}
} -- end of equipinform
tprint (equipinform)
Now to go through it:
print (string.rep ("-", 70))
-- go through each item
for k, v in pairs (equipinform) do
print ""
print ("Doing item", k)
local stats = v.stats
local resists = v.resists
tprint (stats)
print ("This item (" .. v.name .. ") has a damageroll of", stats.damageroll)
end -- for each item
Output:
Doing item 965742031
"hitpoints"=25
"luck"=2
"damageroll"=29
"hitroll"=1
"wisdom"=2
"intelligence"=2
"moves"=-30
This item ((>Asura's Azurite Pearl<)) has a damageroll of 29
Doing item 468263929
This item (V3 Trivia Sleeping Bag) has a damageroll of nil
This isn't exactly "sorting" but it is extracting. If you want to sort you might want to specify what you want to sort on, and what happens if one of the values is nil. For example "V3 Trivia Sleeping Bag" has a damageroll of nil, so it will be hard to sort that. |
- Nick Gammon
www.gammon.com.au, www.mushclient.com | top |
|