Module:HeroDataArrays: Difference between revisions

Jump to navigation Jump to search
mNo edit summary
mNo edit summary
Line 24: Line 24:
if string.find(key, ">") ~= nil then -- If key is actually a path of keys,
if string.find(key, ">") ~= nil then -- If key is actually a path of keys,
local node = heroData          -- starting with the biggest node heroData,
local node = heroData          -- starting with the biggest node heroData,
for k in string.gmatch(key, "([^>]+)") do -- iterate over each key,
for k in string.gmatch(key, "([^>]+)") do -- iterate over each key, separating by ">",
_node = node[k] -- progressing down each node in the path,
if node[k] ~= nil then -- trying the key as a string e.g. "1",
if _node == nil then -- trying the numeric index if the string
node = node[k]
_node = node[tonumber(k)] -- index fails.
else -- else using the key as numeric,
end
node = node[tonumber(k)]
node = _node
end -- drilling down the JSON node after node
end
end
out[key] = node
out[key] = node -- until outputting the final node
else
else
out[key] = heroData[key]
out[key] = heroData[key]