PDA

View Full Version : Lua script question. Error in code logic?



Minty23185Fresh
September 28th, 2017, 22:47
This comes from the 5E ruleset file: 5E\campaign\scripts\power_page.lua, approximately lines 211-225, in the updatePowerGroups() function:



-- Determine all the groups accounted for by current powers
local aPowerGroups = {};
for _,nodePower in pairs(DB.getChildren(getDatabaseNode(), "powers")) do
local sGroup = DB.getValue(nodePower, "group", "");
if sGroup ~= "" then
aPowerGroups[sGroup] = true;
end
end

-- Remove the groups that already exist
for _,vGroup in pairs(aGroups) do
if aPowerGroups[sGroup] then
aPowerGroups[sGroup] = nil;
end
end


My issue is with the sGroup index used in lines 222 and 223. Shouldn't the index be vGroup? sGroup is local to the for loop above in lines 214-216.

Moon Wizard
September 28th, 2017, 23:02
Actually, it should be:



for sGroup,_ in pairs(aGroups) do
if aPowerGroups[sGroup] then
aPowerGroups[sGroup] = nil;
end
end


It didn't end up affecting anything, because there is another check for aGroups[sGroup] existence in the next loop. I've patched for next release (v3.3.3).

Cheers,
JPG