PDA

View Full Version : Need help loading dynamic table(variables)


plastrader
27-10-2006, 06:54 PM
Hi

I'm trying desperatly to get my dynamic savedvariable(table) to load propperly in my mod

the structure of my table looks like htis

VarName = {
["Key1"] = {
["UniqueID1"] = {
["Dynamic2"] = {
["Value1"] = 34,
["Value2"] = 1337012345,
},
},
["UniqueID2"] = {
["Dynamic2"] = {
["Value1"] = 42,
["Value2"] = 13515,
},
},
},
["Key2"] = {
["UniqueID1"] = {
["Dynamic2"] = {
["Value1"] = 34,
["Value2"] = 1337012345,
},
},
["UniqueID2"] = {
["Dynamic2"] = {
["Value1"] = 42,
["Value2"] = 13515,
},
},
},
}


what I want here is to loop through all Dynamic[x] and dig out
UniqueID[x] and summerize the Value[x]

like
["Key1"]["UniqueID1"]["Dynamic2"]["Value1"]
+
["Key1"]["UniqueID2"]["Dynamic2"]["Value1"]
which would be 76

Does it make sense at all?

VarName[1] doesn't work, returns nil...

what should I do?

Thanks in advance.

dafire
27-10-2006, 10:03 PM
you can't use a numeric index on a hash table, since it will search for the key 1 which does not exists.

maybe you could use a loop

http://www.lua.org/pil/4.3.5.html

plastrader
27-10-2006, 10:53 PM
Thanks dafire

I used


for drill1,value in SavedVar do
..
..
for varName,value in SavedVar[drill1][drill2][drill3] do
varName.."="..value
end
..
..
end


Not the prettiest thing in the world perhaps, but it worked. :)

In a later version I use the method mentioned in the link you posted. :azn: