Module:HeroDataArrays: Difference between revisionsGive feedback
SerpentofSet (talk | contribs) mNo edit summary |
SerpentofSet (talk | contribs) 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 ">", | ||
if node[k] ~= nil then -- trying the key as a string e.g. "1", | |||
node = node[k] | |||
else -- else using the key as numeric, | |||
end | node = node[tonumber(k)] | ||
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] | ||