Module:HeroDataArrays: Difference between revisions

mNo edit summary
m better (?) comments
Line 19: Line 19:
local outData = {}
local outData = {}
for i, heroData in ipairs(inGameHeroData) do -- Iterate over each hero
for i, heroData in ipairs(inGameHeroData) do -- Iterate over each hero
local out = {}
local out = {} -- First creating a table to hold data
for j, key in pairs(args) do
for j, key in pairs(args) do -- Iterate over each key:
if string.find(key, ">") ~= nil then -- If key is actually a path of keys,
if string.find(key, ">") ~= nil then -- If the key is actually a path of keys,
local node = heroData          -- starting with the biggest node heroData,
local node = heroData          -- start with the biggest node heroData, and
for k in string.gmatch(key, "([^>]+)") do -- iterate over each key, separating by ">",
for k in string.gmatch(key, "([^>]+)") do -- iterate over each key, splitting on ">",
if node[k] ~= nil then -- trying the key as a string e.g. "1",
if node[k] ~= nil then -- trying the key as a string e.g. "1",
node = node[k]
node = node[k]
Line 33: Line 33:
out[key] = node -- until outputting the final node
out[key] = node -- until outputting the final node
else
else
out[key] = heroData[key]
out[key] = heroData[key] -- or just grab the data if not a path
end
end
end
end
outData[heroData["Name"]] = out
outData[heroData["Name"]] = out -- Save data in the big table of heroes
end
end
return(outData)
return(outData)