From ac80962c9c0b5874360c1c1e02bac60da42300a5 Mon Sep 17 00:00:00 2001 From: Chr1Z93 Date: Tue, 19 Nov 2024 00:18:00 +0100 Subject: [PATCH] some nil handling --- src/core/MythosArea.ttslua | 2 +- src/playercards/CardsThatSealTokens.ttslua | 11 ++++++++--- src/playermat/Playermat.ttslua | 2 +- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/core/MythosArea.ttslua b/src/core/MythosArea.ttslua index 3c0a1c0a..36d38d5c 100644 --- a/src/core/MythosArea.ttslua +++ b/src/core/MythosArea.ttslua @@ -163,7 +163,7 @@ end -- Listens for cards entering the encounter deck or encounter discard, discards tokens on them, -- and resets the spawn state for the cards when they do. -function onObjectEnterContainer(container, object) +function tryObjectEnterContainer(container, object) local localPos = self.positionToLocal(container.getPosition()) if inArea(localPos, ENCOUNTER_DECK_AREA) or inArea(localPos, ENCOUNTER_DISCARD_AREA) then tokenSpawnTrackerApi.resetTokensSpawned(object) diff --git a/src/playercards/CardsThatSealTokens.ttslua b/src/playercards/CardsThatSealTokens.ttslua index c92801e5..74eaf35b 100644 --- a/src/playercards/CardsThatSealTokens.ttslua +++ b/src/playercards/CardsThatSealTokens.ttslua @@ -360,11 +360,15 @@ function resolveSealed(playerColor) broadcastToAll("No tokens sealed.", "Red") return end + local closestMatColor = playermatApi.getMatColorByPosition(self.getPosition()) local mat = guidReferenceApi.getObjectByOwnerAndType(closestMatColor, "Playermat") local guidToBeResolved = table.remove(sealedTokens) local resolvedToken = getObjectFromGUID(guidToBeResolved) - resolvedToken.UI.setXml("") + if resolvedToken ~= nil then + resolvedToken.UI.setXml("") + end + updateStackSize() updateSave() chaosBagApi.drawChaosToken(mat, true, _, guidToBeResolved) @@ -374,9 +378,10 @@ end function updateStackSize() if MAX_SEALED == 1 then return end if #sealedTokens == 0 then return end + -- get topmost sealed token local topToken = getObjectFromGUID(sealedTokens[#sealedTokens]) - local name = topToken.getName() + if topToken == nil then return end topToken.UI.setXmlTable({ { @@ -387,7 +392,7 @@ function updateStackSize() rotation = "0 0 180", scale = "0.2 0.2 1", position = "0 0 -12", - color = tokenColor[name] or "#77674DE6" + color = tokenColor[topToken.getName()] or "#77674DE6" }, children = { tag = "Text", diff --git a/src/playermat/Playermat.ttslua b/src/playermat/Playermat.ttslua index e7619a1e..da8b350d 100644 --- a/src/playermat/Playermat.ttslua +++ b/src/playermat/Playermat.ttslua @@ -1335,7 +1335,7 @@ function spawnTokensOrShowHelper(card) end end -function onObjectEnterContainer(container, object) +function tryObjectEnterContainer(container, object) if object.type ~= "Card" then return end local localCardPos = self.positionToLocal(object.getPosition())