Module:NpcData: Difference between revisionsGive feedback
Jump to navigation
Jump to search
Added `get_nested_var` function for accessing nested data |
Fixed get_nested_var to handle numeric-string keys |
||
| Line 128: | Line 128: | ||
local value = npc | local value = npc | ||
for key in string.gmatch(path, '([^.]+)') do | for key in string.gmatch(path, '([^.]+)') do | ||
if type(value) ~= "table" then | |||
return '<span class="error">Error: Path "' .. path .. '" is invalid.</span>' | |||
end | |||
-- try first with the raw key, then with a number conversion | |||
local next = value[key] or value[tonumber(key)] or value[tostring(key)] | |||
if next == nil then | |||
return '<span class="error">Error: Key "' .. key .. '" not found in path.</span>' | |||
end | |||
value = next | |||
end | end | ||