error handling

This commit is contained in:
Chr1Z93 2024-02-16 11:28:44 +01:00
parent aabaf52d96
commit 2b077599fb

View File

@ -31,10 +31,10 @@ function generate(_, playerColor)
idList = {} idList = {}
for _, obj in ipairs(searchLib.onObject(self, "isCardOrDeck")) do for _, obj in ipairs(searchLib.onObject(self, "isCardOrDeck")) do
if obj.type == "Card" then if obj.type == "Card" then
processCard(JSON.decode(obj.getGMNotes()), obj.getName(), playerColor) processCard(obj.getGMNotes(), obj.getName(), playerColor)
elseif obj.type == "Deck" then elseif obj.type == "Deck" then
for _, deepObj in ipairs(obj.getData().ContainedObjects) do for _, deepObj in ipairs(obj.getData().ContainedObjects) do
processCard(JSON.decode(deepObj.GMNotes), deepObj.Nickname, playerColor) processCard(deepObj.GMNotes, deepObj.Nickname, playerColor)
end end
end end
end end
@ -69,15 +69,13 @@ function getIdFromData(metadata)
end end
end end
function processCard(metadata, name, playerColor) function processCard(notes, name, playerColor)
if metadata then local id = getIdFromData(JSON.decode(notes) or {})
local id = getIdFromData(metadata)
if id then if id then
table.insert(idList, {id = id, name = name}) table.insert(idList, {id = id, name = name})
else else
broadcastToColor("Couldn't get ID for " .. name .. ".", playerColor, "Red") broadcastToColor("Couldn't get ID for " .. name .. ".", playerColor, "Red")
end end
end
end end
function sortById(a, b) function sortById(a, b)