Set a default value for to.lockedToThis in the first iteration of the loop

This commit is contained in:
Luca_S
2020-05-09 20:23:45 +02:00
parent 94477e5d98
commit 21b4d7a78c

View File

@@ -374,9 +374,9 @@ function Storage:defrag(throttle)
-- are ruled out by the condition of the outer while loop
for i = 2, #providers do
-- Give preference to locked chests
if not to.lockedToThis and providers[i].lockedToThis then
if not (to and to.lockedToThis or false) and providers[i].lockedToThis then
to = providers[i]
elseif (to.lockedToThis == providers[i].lockedToThis) and providers[i].item.count < providers[i].item.maxCount then
elseif ((to and to.lockedToThis or false) == providers[i].lockedToThis) and providers[i].item.count < providers[i].item.maxCount then
to = providers[i]
elseif providers[i].item.count == providers[i].item.maxCount then
-- As this slot is already at maxCount, all the remaining ones will also be due to sorting