Skip to content

Commit

Permalink
chore: improve error handling and logging in Game storage functions
Browse files Browse the repository at this point in the history
  • Loading branch information
omarcopires committed Feb 19, 2024
1 parent 5bbb0b0 commit 2db9804
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions data/libs/functions/game.lua
Original file line number Diff line number Diff line change
Expand Up @@ -82,21 +82,22 @@ if not globalStorageTable then
end

function Game.getStorageValue(key)
return globalStorageTable[key] or -1
if type(globalStorageTable) == "table" and key ~= nil then
return globalStorageTable[key] or -1
else
logger.error("[Game.getStorageValue] Invalid table or key: {}", key)
return -1
end
end

function Game.setStorageValue(key, value)
if key == nil then
logger.error("[Game.setStorageValue] Key is nil")
return
end

if value == -1 then
if globalStorageTable[key] then
if type(globalStorageTable) == "table" and key ~= nil then
if value == -1 then
globalStorageTable[key] = nil
else
globalStorageTable[key] = value
end
return
else
logger.error("[Game.setStorageValue] Invalid table or key: {}", key)
end

globalStorageTable[key] = value
end

0 comments on commit 2db9804

Please sign in to comment.