Module:GameData: Difference between revisionsGive feedback
m remove weapon dive, clean comments a bit |
Support numeric array indices in dot notation for Upgrades etc (with help from vergir-bot LLM) |
||
| Line 110: | Line 110: | ||
end | end | ||
-- Traverse a table using dot notation, unwrap tables with a .Value field | -- Traverse a table using dot notation, unwrap tables with a .Value field. | ||
-- Supports numeric indices for arrays (e.g. "Upgrades.1.WeaponDamageBonus"). | |||
local function resolve_prop(tbl, prop) | local function resolve_prop(tbl, prop) | ||
if not prop or prop == "" then return nil end | if not prop or prop == "" then return nil end | ||
| Line 116: | Line 117: | ||
for segment in string.gmatch(prop, "[^%.]+") do | for segment in string.gmatch(prop, "[^%.]+") do | ||
if type(element) ~= "table" then return nil end | if type(element) ~= "table" then return nil end | ||
element = element[ | local next = element[segment] | ||
if next == nil then | |||
local num = tonumber(segment) | |||
if num then next = element[num] end | |||
end | |||
element = next | |||
if element == nil then return nil end | if element == nil then return nil end | ||
end | end | ||