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 = {}
for _, obj in ipairs(searchLib.onObject(self, "isCardOrDeck")) do
if obj.type == "Card" then
processCard(JSON.decode(obj.getGMNotes()), obj.getName(), playerColor)
processCard(obj.getGMNotes(), obj.getName(), playerColor)
elseif obj.type == "Deck" then
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
@ -69,14 +69,12 @@ function getIdFromData(metadata)
end
end
function processCard(metadata, name, playerColor)
if metadata then
local id = getIdFromData(metadata)
if id then
table.insert(idList, {id = id, name = name})
else
broadcastToColor("Couldn't get ID for " .. name .. ".", playerColor, "Red")
end
function processCard(notes, name, playerColor)
local id = getIdFromData(JSON.decode(notes) or {})
if id then
table.insert(idList, {id = id, name = name})
else
broadcastToColor("Couldn't get ID for " .. name .. ".", playerColor, "Red")
end
end