From 3093169967c95ad5b7453dc3a64cdf0a08f8d77b Mon Sep 17 00:00:00 2001 From: Christopher Brown Date: Fri, 29 Sep 2023 11:04:23 +1000 Subject: [PATCH 01/12] Functionalise the code for checking if an expansion has events. It was repeated four times throughout the SetupChecker script. --- objects/SetupChecker/script.lua | 35 ++++++++------------------------- 1 file changed, 8 insertions(+), 27 deletions(-) diff --git a/objects/SetupChecker/script.lua b/objects/SetupChecker/script.lua index f7811f9bf..73cd82430 100644 --- a/objects/SetupChecker/script.lua +++ b/objects/SetupChecker/script.lua @@ -340,15 +340,8 @@ function onLoad(saved_data) updatePlaytestExpansionList(expansions), } for expansion,guid in pairs(expansions) do - local hasEvents = false - for _,obj in pairs(getObjectFromGUID(guid).getObjects()) do - if obj.name == "Events" then - hasEvents = true - break - end - end table.insert(funcList, addExpansionToggle(expansion)) - if hasEvents then + if expansionHasEvents(getObjectFromGUID(guid)) then table.insert(funcList, addEventToggle(expansion)) end end @@ -460,7 +453,7 @@ function newAdversaryScenario(obj, adversary, disabled) } }, {}) end -function addExpansion(bag) +function expansionHasEvents(bag) local hasEvents = false for _,obj in pairs(bag.getObjects()) do if obj.name == "Events" then @@ -468,9 +461,12 @@ function addExpansion(bag) break end end + return hasEvents +end +function addExpansion(bag) if not expansions[bag.getName()] then local funcList = {addExpansionToggle(bag.getName())} - if hasEvents then + if expansionHasEvents(bag) then table.insert(funcList, addEventToggle(bag.getName())) end updateXml(self, funcList) @@ -912,15 +908,7 @@ function toggleExpansion(_, _, id) Global.setTable("expansions", exps) self.UI.setAttribute(id, "isOn", bool) - local hasEvents = false - for _,obj in pairs(getObjectFromGUID(expansions[id]).getObjects()) do - if obj.name == "Events" then - hasEvents = true - break - end - end - - if hasEvents then + if expansionHasEvents(getObjectFromGUID(expansions[id])) then local events = Global.getTable("events") events[id] = exps[id] Global.setTable("events", events) @@ -962,14 +950,7 @@ function toggleAllEvents() local exps = Global.getTable("expansions") for exp,enabled in pairs(exps) do if enabled then - local hasEvents = false - for _,obj in pairs(getObjectFromGUID(expansions[exp]).getObjects()) do - if obj.name == "Events" then - hasEvents = true - break - end - end - if hasEvents then + if expansionHasEvents(getObjectFromGUID(expansions[exp])) then events[exp] = true toggleEvents(nil, nil, exp.." Events") end From 8e44d49ba0a558fcca89c8683bf8e29a246efe76 Mon Sep 17 00:00:00 2001 From: Christopher Brown Date: Fri, 29 Sep 2023 11:33:06 +1000 Subject: [PATCH 02/12] Always update the playtest expansions in removeExpansion(). For some reason, the list of playtest expansions was only updated if the removed expansion was the current playtest expansion. But the list should be updated even if a non-selected element is being removed from it. --- objects/SetupChecker/script.lua | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/objects/SetupChecker/script.lua b/objects/SetupChecker/script.lua index 73cd82430..93985e122 100644 --- a/objects/SetupChecker/script.lua +++ b/objects/SetupChecker/script.lua @@ -538,10 +538,8 @@ function removeExpansion(bag) local funcList = { removeToggle("expansionsRow", bag.getName()), removeToggle("events", bag.getName().." Events"), + updatePlaytestExpansionList(exps), } - if playtestExpansion == bag.getName() then - table.insert(funcList, updatePlaytestExpansionList(exps)) - end updateXml(self, funcList) Wait.frames(updateRequiredContent, 1) From f3c0dbe636dc50d0fd047707100e4664ba01aeed Mon Sep 17 00:00:00 2001 From: Christopher Brown Date: Fri, 29 Sep 2023 11:36:47 +1000 Subject: [PATCH 03/12] Change the toggle row height to use ceil instead of floor. It was using floor((x+1)/2) instead of ceil(x/2). They produce the same results (for integers), but ceil is the more natural representation, and would keep working it the number of elements per row were changed to a number other than 2. --- objects/SetupChecker/script.lua | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/objects/SetupChecker/script.lua b/objects/SetupChecker/script.lua index 93985e122..763bcd0de 100644 --- a/objects/SetupChecker/script.lua +++ b/objects/SetupChecker/script.lua @@ -2459,7 +2459,7 @@ function addExpansionToggle(value) children={}, }) local count = #t.children[1].children[1].children - t.attributes["preferredHeight"] = math.floor((count + 1) / 2) * 60 + 0.1 + t.attributes["preferredHeight"] = math.ceil(count / 2) * 60 + 0.1 end) end function addEventToggle(value) @@ -2471,7 +2471,7 @@ function addEventToggle(value) children={}, }) local count = #t.children[1].children[1].children - t.attributes["preferredHeight"] = math.floor((count + 1) / 2) * 60 + 0.1 + t.attributes["preferredHeight"] = math.ceil(count / 2) * 60 + 0.1 end) end function removeToggle(id, value) @@ -2483,7 +2483,7 @@ function removeToggle(id, value) end end local count = #t.children[1].children[1].children - t.attributes["preferredHeight"] = math.floor((count + 1) / 2) * 60 + 0.1 + t.attributes["preferredHeight"] = math.ceil(count / 2) * 60 + 0.1 end) end From bbdc696c8dfb530ece7491ab4e6e8a9a1b48bf6a Mon Sep 17 00:00:00 2001 From: Christopher Brown Date: Sat, 30 Sep 2023 16:13:51 +1000 Subject: [PATCH 04/12] Make removeExpansion() also disable events for the removed expansion. --- objects/SetupChecker/script.lua | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/objects/SetupChecker/script.lua b/objects/SetupChecker/script.lua index 763bcd0de..de4816c5c 100644 --- a/objects/SetupChecker/script.lua +++ b/objects/SetupChecker/script.lua @@ -530,10 +530,15 @@ function onObjectDestroy(obj) end end function removeExpansion(bag) + expansions[bag.getName()] = nil + local exps = Global.getTable("expansions") exps[bag.getName()] = nil Global.setTable("expansions", exps) - expansions[bag.getName()] = nil + + local events = Global.getTable("events") + events[bag.getName()] = nil + Global.setTable("events", events) local funcList = { removeToggle("expansionsRow", bag.getName()), From 0302bbfc652ea36bf1a33379a861b30499590f5a Mon Sep 17 00:00:00 2001 From: Christopher Brown Date: Fri, 29 Sep 2023 11:40:19 +1000 Subject: [PATCH 05/12] Replace add*Toggle() and removeToggle() with update*Toggles(). For updating the expansion and event toggles in the SetupChecker UI. This is robust to multiple calls, and thus should be easier to work with in future. --- objects/SetupChecker/script.lua | 93 ++++++++++++++------------------- 1 file changed, 39 insertions(+), 54 deletions(-) diff --git a/objects/SetupChecker/script.lua b/objects/SetupChecker/script.lua index de4816c5c..b994b9d88 100644 --- a/objects/SetupChecker/script.lua +++ b/objects/SetupChecker/script.lua @@ -336,29 +336,15 @@ function onLoad(saved_data) local funcList = { updateAdversaryList(), updateScenarioList(), + updateExpansionToggles(), + updateEventToggles(), updateBoardLayouts(numPlayers), updatePlaytestExpansionList(expansions), } - for expansion,guid in pairs(expansions) do - table.insert(funcList, addExpansionToggle(expansion)) - if expansionHasEvents(getObjectFromGUID(guid)) then - table.insert(funcList, addEventToggle(expansion)) - end - end updateXml(self, funcList) Wait.frames(function() toggleSimpleMode() toggleChallenge() - local events = Global.getTable("events") - for expansion, enabled in pairs(Global.getTable("expansions")) do - if enabled then - self.UI.setAttribute(expansion, "isOn", "true") - if events[expansion] then - self.UI.setAttribute(expansion.." Events", "isOn", "true") - end - end - end - updateDifficulty() end, 2) end, 2) @@ -464,14 +450,8 @@ function expansionHasEvents(bag) return hasEvents end function addExpansion(bag) - if not expansions[bag.getName()] then - local funcList = {addExpansionToggle(bag.getName())} - if expansionHasEvents(bag) then - table.insert(funcList, addEventToggle(bag.getName())) - end - updateXml(self, funcList) - end expansions[bag.getName()] = bag.guid + updateXml(self, {updateExpansionToggles(), updateEventToggles()}) end function addAdversary(obj) if adversaries[obj.getName()] == nil then @@ -541,8 +521,8 @@ function removeExpansion(bag) Global.setTable("events", events) local funcList = { - removeToggle("expansionsRow", bag.getName()), - removeToggle("events", bag.getName().." Events"), + updateExpansionToggles(), + updateEventToggles(), updatePlaytestExpansionList(exps), } updateXml(self, funcList) @@ -2455,41 +2435,46 @@ function updateDropdownSelection(id, value) end) end -function addExpansionToggle(value) - return matchRecurse("expansionsRow", function (t) - table.insert(t.children[1].children[1].children, { - tag="Toggle", - value=value, - attributes={id = value, onValueChanged = "toggleExpansion"}, - children={}, - }) +-- Update a 2-width grid of toggle buttons to the have the given items and states +-- @param id The id of the row containing the grid of toggles +-- @param values A table mapping toggle names to boolean values +-- @param onValueChanged The name of the function to call when a toggle is clicked +function updateToggleGrid(id, values, onValueChanged) + return matchRecurse(id, function (t) + t.children[1].children[1].children = {} + for name,isOn in pairs(values) do + table.insert(t.children[1].children[1].children, { + tag="Toggle", + value=name, + attributes={id = name, onValueChanged = onValueChanged, isOn = tostring(isOn)}, + children={}, + }) + end local count = #t.children[1].children[1].children t.attributes["preferredHeight"] = math.ceil(count / 2) * 60 + 0.1 end) end -function addEventToggle(value) - return matchRecurse("events", function (t) - table.insert(t.children[1].children[1].children, { - tag="Toggle", - value=value.." Events", - attributes={id = value.." Events", onValueChanged = "toggleEvents"}, - children={}, - }) - local count = #t.children[1].children[1].children - t.attributes["preferredHeight"] = math.ceil(count / 2) * 60 + 0.1 - end) +function updateExpansionToggles() + local exps = Global.getTable("expansions") + local values = {} + for name,_ in pairs(expansions) do + -- The Global expansions table stores nil for disabled expansions + -- We want a boolean false, so we explicitly check for equality to true + values[name] = (exps[name] == true) + end + return updateToggleGrid("expansionsRow", values, "toggleExpansion") end -function removeToggle(id, value) - return matchRecurse(id, function (t) - for i,child in pairs(t.children[1].children[1].children) do - if child.value == value then - table.remove(t.children[1].children[1].children, i) - break - end +function updateEventToggles() + local events = Global.getTable("events") + local values = {} + for name,guid in pairs(expansions) do + if expansionHasEvents(getObjectFromGUID(guid)) then + -- The Global events table stores nil for disabled expansions + -- We want a boolean false, so we explicitly check for equality to true + values[name.." Events"] = (events[name] == true) end - local count = #t.children[1].children[1].children - t.attributes["preferredHeight"] = math.ceil(count / 2) * 60 + 0.1 - end) + end + return updateToggleGrid("events", values, "toggleEvents") end function updateAdversaryUI(params) From ddd834b553852b241177564ef7789e10d51e58d8 Mon Sep 17 00:00:00 2001 From: Christopher Brown Date: Fri, 29 Sep 2023 11:59:57 +1000 Subject: [PATCH 06/12] Fix a bug with the playtest expansions list when loading a save. SetupChecker's updatePlaytestExpansionList() function expects the Global-style table of expansions (mapping names to booleans), not the SetupChecker-style table of expansions (mapping names to GUIDs). SetupChecker's onLoad() gives it the SetupChecker-style table of expansions, and thus it would treat all expansions as being enabled. Fix this by having it not take an argument at all, and just fetch the table of expansions from Global itself. --- objects/SetupChecker/script.lua | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/objects/SetupChecker/script.lua b/objects/SetupChecker/script.lua index b994b9d88..998a91ff7 100644 --- a/objects/SetupChecker/script.lua +++ b/objects/SetupChecker/script.lua @@ -339,7 +339,7 @@ function onLoad(saved_data) updateExpansionToggles(), updateEventToggles(), updateBoardLayouts(numPlayers), - updatePlaytestExpansionList(expansions), + updatePlaytestExpansionList(), } updateXml(self, funcList) Wait.frames(function() @@ -523,7 +523,7 @@ function removeExpansion(bag) local funcList = { updateExpansionToggles(), updateEventToggles(), - updatePlaytestExpansionList(exps), + updatePlaytestExpansionList(), } updateXml(self, funcList) @@ -913,7 +913,7 @@ function toggleExpansion(_, _, id) end updateDifficulty() - Wait.frames(function() updateXml(self, {updatePlaytestExpansionList(exps)}) end, 1) + Wait.frames(function() updateXml(self, {updatePlaytestExpansionList()}) end, 1) Wait.frames(updateRequiredContent, 2) end function toggleAllEvents() @@ -972,10 +972,10 @@ function toggleEvents(_, _, id) self.UI.setAttribute(id, "isOn", bool) end -function updatePlaytestExpansionList(exps) +function updatePlaytestExpansionList() local playtestExpansions = {"None"} local found = false - for name,enabled in pairs(exps) do + for name,enabled in pairs(Global.getTable("expansions")) do if enabled then table.insert(playtestExpansions, name) if playtestExpansion == name then From 8809da8beecbc6168098600781819b0f983661fb Mon Sep 17 00:00:00 2001 From: Christopher Brown Date: Fri, 29 Sep 2023 12:07:37 +1000 Subject: [PATCH 07/12] Make updateBoardLayouts() require no argument. It simply required the number of players, which it can fetch for itself. --- objects/SetupChecker/script.lua | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/objects/SetupChecker/script.lua b/objects/SetupChecker/script.lua index 998a91ff7..cc0d04dde 100644 --- a/objects/SetupChecker/script.lua +++ b/objects/SetupChecker/script.lua @@ -338,7 +338,7 @@ function onLoad(saved_data) updateScenarioList(), updateExpansionToggles(), updateEventToggles(), - updateBoardLayouts(numPlayers), + updateBoardLayouts(), updatePlaytestExpansionList(), } updateXml(self, funcList) @@ -653,13 +653,13 @@ function updateNumPlayers(value, updateUI) if updateLayoutsID ~= 0 then Wait.stop(updateLayoutsID) end - updateLayoutsID = Wait.time(function() updateXml(self, {updateBoardLayouts(numPlayers)}) end, 0.5) + updateLayoutsID = Wait.time(function() updateXml(self, {updateBoardLayouts()}) end, 0.5) end end -function updateBoardLayouts(numPlayers) - local numBoards = numPlayers +function updateBoardLayouts() + local numBoards = Global.getVar("numPlayers") if optionalExtraBoard then - numBoards = numPlayers + 1 + numBoards = numBoards + 1 end local layoutNames = { "Balanced" } local alternateBoardLayoutNames = Global.getVar("alternateBoardLayoutNames") @@ -668,7 +668,7 @@ function updateBoardLayouts(numPlayers) table.insert(layoutNames, layout) end end - local canThematic = numPlayers < 6 or (numPlayers == 6 and not optionalExtraBoard) + local canThematic = (numBoards <= 6) if canThematic then table.insert(layoutNames, "Thematic") end @@ -2183,7 +2183,7 @@ function toggleExtraBoard() if updateLayoutsID ~= 0 then Wait.stop(updateLayoutsID) end - updateLayoutsID = Wait.time(function() updateXml(self, {updateBoardLayouts(numPlayers)}) end, 0.5) + updateLayoutsID = Wait.time(function() updateXml(self, {updateBoardLayouts()}) end, 0.5) end end function toggleBoardPairings() From 9883317c719da3e81f9d352524eb8b36900be900 Mon Sep 17 00:00:00 2001 From: Christopher Brown Date: Fri, 29 Sep 2023 12:33:00 +1000 Subject: [PATCH 08/12] Always bundle together all updateXml() calls on SetupChecker. To avoid race conditions. --- objects/SetupChecker/script.lua | 46 ++++++++++++++++----------------- 1 file changed, 22 insertions(+), 24 deletions(-) diff --git a/objects/SetupChecker/script.lua b/objects/SetupChecker/script.lua index cc0d04dde..17748f68f 100644 --- a/objects/SetupChecker/script.lua +++ b/objects/SetupChecker/script.lua @@ -331,17 +331,8 @@ function onLoad(saved_data) newAdversaryScenario(getObjectFromGUID(guid), false, scenarios[name] == nil) end - -- queue up all dropdown changes at once Wait.frames(function() - local funcList = { - updateAdversaryList(), - updateScenarioList(), - updateExpansionToggles(), - updateEventToggles(), - updateBoardLayouts(), - updatePlaytestExpansionList(), - } - updateXml(self, funcList) + updateSelfXml() Wait.frames(function() toggleSimpleMode() toggleChallenge() @@ -383,6 +374,18 @@ function onObjectSpawn(obj) end end end +function updateSelfXml() + -- Bundles all updates to own UI XML together, to prevent race conditions. + local funcList = { + updateAdversaryList(), + updateScenarioList(), + updateExpansionToggles(), + updateEventToggles(), + updateBoardLayouts(), + updatePlaytestExpansionList(), + } + updateXml(self, funcList) +end function toggleAdversary(_, value, adversary) local obj = getObjectFromGUID(allAdversaries[adversary]) if value == "True" then @@ -451,7 +454,7 @@ function expansionHasEvents(bag) end function addExpansion(bag) expansions[bag.getName()] = bag.guid - updateXml(self, {updateExpansionToggles(), updateEventToggles()}) + updateSelfXml() end function addAdversary(obj) if adversaries[obj.getName()] == nil then @@ -460,7 +463,7 @@ function addAdversary(obj) return end adversaries[obj.getName()] = obj.guid - Wait.frames(function() updateXml(self, {updateAdversaryList()}) end, 1) + Wait.frames(updateSelfXml, 1) end function addScenario(obj) if scenarios[obj.getName()] == nil then @@ -469,7 +472,7 @@ function addScenario(obj) return end scenarios[obj.getName()] = obj.guid - Wait.frames(function() updateXml(self, {updateScenarioList()}) end, 1) + Wait.frames(updateSelfXml, 1) end function onDestroy() exit = true @@ -520,12 +523,7 @@ function removeExpansion(bag) events[bag.getName()] = nil Global.setTable("events", events) - local funcList = { - updateExpansionToggles(), - updateEventToggles(), - updatePlaytestExpansionList(), - } - updateXml(self, funcList) + updateSelfXml() Wait.frames(updateRequiredContent, 1) end @@ -542,7 +540,7 @@ function removeAdversary(obj) Global.setVar("adversaryCard2", nil) toggleSupportingLevel(nil, 0) end - Wait.frames(function() updateXml(self, {updateAdversaryList()}) end, 1) + Wait.frames(updateSelfXml, 1) break end end @@ -583,7 +581,7 @@ function removeScenario(obj) Global.setVar("scenarioCard", nil) updateDifficulty() end - Wait.frames(function() updateXml(self, {updateScenarioList()}) end, 1) + Wait.frames(updateSelfXml, 1) break end end @@ -653,7 +651,7 @@ function updateNumPlayers(value, updateUI) if updateLayoutsID ~= 0 then Wait.stop(updateLayoutsID) end - updateLayoutsID = Wait.time(function() updateXml(self, {updateBoardLayouts()}) end, 0.5) + updateLayoutsID = Wait.time(updateSelfXml, 0.5) end end function updateBoardLayouts() @@ -913,7 +911,7 @@ function toggleExpansion(_, _, id) end updateDifficulty() - Wait.frames(function() updateXml(self, {updatePlaytestExpansionList()}) end, 1) + Wait.frames(updateSelfXml, 1) Wait.frames(updateRequiredContent, 2) end function toggleAllEvents() @@ -2183,7 +2181,7 @@ function toggleExtraBoard() if updateLayoutsID ~= 0 then Wait.stop(updateLayoutsID) end - updateLayoutsID = Wait.time(function() updateXml(self, {updateBoardLayouts()}) end, 0.5) + updateLayoutsID = Wait.time(updateSelfXml, 0.5) end end function toggleBoardPairings() From 341712fd4c7216a77aa0f6a5495777c4113e568d Mon Sep 17 00:00:00 2001 From: Christopher Brown Date: Fri, 29 Sep 2023 12:38:08 +1000 Subject: [PATCH 09/12] Make newly added expansions default to being enabled. --- objects/SetupChecker/script.lua | 1 + 1 file changed, 1 insertion(+) diff --git a/objects/SetupChecker/script.lua b/objects/SetupChecker/script.lua index 17748f68f..acb51783a 100644 --- a/objects/SetupChecker/script.lua +++ b/objects/SetupChecker/script.lua @@ -455,6 +455,7 @@ end function addExpansion(bag) expansions[bag.getName()] = bag.guid updateSelfXml() + Wait.frames(function() toggleExpansion(_, _, bag.getName()) end, 1) end function addAdversary(obj) if adversaries[obj.getName()] == nil then From 93e0ab0e4d505496f04efcd9906e146c76e7d4c6 Mon Sep 17 00:00:00 2001 From: Christopher Brown Date: Sat, 30 Sep 2023 16:44:58 +1000 Subject: [PATCH 10/12] Pass nil instead of _ to toggleExpansion() in addExpansion(). The linter rightly called me up on this. --- objects/SetupChecker/script.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/objects/SetupChecker/script.lua b/objects/SetupChecker/script.lua index acb51783a..4a2528149 100644 --- a/objects/SetupChecker/script.lua +++ b/objects/SetupChecker/script.lua @@ -455,7 +455,7 @@ end function addExpansion(bag) expansions[bag.getName()] = bag.guid updateSelfXml() - Wait.frames(function() toggleExpansion(_, _, bag.getName()) end, 1) + Wait.frames(function() toggleExpansion(nil, nil, bag.getName()) end, 1) end function addAdversary(obj) if adversaries[obj.getName()] == nil then From 7ae6a4d62c69f90bdb20c95d734cd381bd0f757d Mon Sep 17 00:00:00 2001 From: Christopher Brown Date: Sun, 1 Oct 2023 01:51:23 +1000 Subject: [PATCH 11/12] Make expansionHasEvents() take a GUID, not object reference. All calls to it were now using a GUID and fetching the object reference from that, so it might as well fetch the object reference internally. --- objects/SetupChecker/script.lua | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/objects/SetupChecker/script.lua b/objects/SetupChecker/script.lua index 4a2528149..4f687b902 100644 --- a/objects/SetupChecker/script.lua +++ b/objects/SetupChecker/script.lua @@ -442,7 +442,8 @@ function newAdversaryScenario(obj, adversary, disabled) } }, {}) end -function expansionHasEvents(bag) +function expansionHasEvents(bagGUID) + local bag = getObjectFromGUID(bagGUID) local hasEvents = false for _,obj in pairs(bag.getObjects()) do if obj.name == "Events" then @@ -890,7 +891,7 @@ function toggleExpansion(_, _, id) Global.setTable("expansions", exps) self.UI.setAttribute(id, "isOn", bool) - if expansionHasEvents(getObjectFromGUID(expansions[id])) then + if expansionHasEvents(expansions[id]) then local events = Global.getTable("events") events[id] = exps[id] Global.setTable("events", events) @@ -932,7 +933,7 @@ function toggleAllEvents() local exps = Global.getTable("expansions") for exp,enabled in pairs(exps) do if enabled then - if expansionHasEvents(getObjectFromGUID(expansions[exp])) then + if expansionHasEvents(expansions[exp]) then events[exp] = true toggleEvents(nil, nil, exp.." Events") end @@ -2467,7 +2468,7 @@ function updateEventToggles() local events = Global.getTable("events") local values = {} for name,guid in pairs(expansions) do - if expansionHasEvents(getObjectFromGUID(guid)) then + if expansionHasEvents(guid) then -- The Global events table stores nil for disabled expansions -- We want a boolean false, so we explicitly check for equality to true values[name.." Events"] = (events[name] == true) From 35e69b8c84051274fc84f391605690008095f642 Mon Sep 17 00:00:00 2001 From: Christopher Brown Date: Sun, 1 Oct 2023 01:53:45 +1000 Subject: [PATCH 12/12] Add a nil check to expansionHasEvents(). This prevents an error message when removing multiple expansions simultaneously. --- objects/SetupChecker/script.lua | 3 +++ 1 file changed, 3 insertions(+) diff --git a/objects/SetupChecker/script.lua b/objects/SetupChecker/script.lua index 4f687b902..931cc50b3 100644 --- a/objects/SetupChecker/script.lua +++ b/objects/SetupChecker/script.lua @@ -444,6 +444,9 @@ function newAdversaryScenario(obj, adversary, disabled) end function expansionHasEvents(bagGUID) local bag = getObjectFromGUID(bagGUID) + if bag == nil then + return false + end local hasEvents = false for _,obj in pairs(bag.getObjects()) do if obj.name == "Events" then