Catch all return values from pcall

This commit is contained in:
Gabriel Tofvesson 2024-11-28 00:32:41 +01:00
parent 30b49215a6
commit cd73609a2e

View File

@ -199,25 +199,27 @@ function ItemStack:transferTo(target, count)
return count == 0, 0
end
local result, xfer = pcall(self:getInventory().pushItems, peripheral.getName(target:getInventory()), self:getSlot(), cap, target:getSlot())
local result = { pcall(self:getInventory().pushItems, peripheral.getName(target:getInventory()), self:getSlot(), cap, target:getSlot()) }
if not result then
return false, xfer
if not result[1] then
return false, result[2]
end
if xfer == nil then
if result[2] == nil then
Logger:error(
"Error transferring item", self:getInventory().pushItems, Logger.plain("\n"),
peripheral.getName(target:getInventory()), Logger.plain("\n"),
self:getSlot(), cap, Logger.plain("\n"),
target
cap, Logger.plain("\n"),
self, Logger.plain("\n"),
target, Logger.plain("\n"),
result
)
end
target:_modify(xfer, self)
self:_modify(-xfer, self)
target:_modify(result[2], self)
self:_modify(-result[2], self)
return xfer == count, xfer
return result[2] == count, result[2]
end
local function objEquals(o1, o2)