diff --git a/itemcontroller.lua b/itemcontroller.lua index 3e5c3e8..203674c 100644 --- a/itemcontroller.lua +++ b/itemcontroller.lua @@ -43,29 +43,27 @@ local function saveState(fname, ctrl) end local function loadState(fname, node) - local controller = nil if not isLocked() then + print("Not locked! Loading cache...") local file = fs.open(fname, "r") if file ~= nil then local ser = textutils.unserialize(file.readAll()) file.close() return Storage:fromSerializable(ser) end - controller = loadState(fname) end - if controller == nil then - local nodeName = peripheral.getName(node) - local storageChests = {peripheral.find("inventory")} - for i,v in ipairs(storageChests) do - if peripheral.getName(v) == nodeName then - table.remove(storageChests, i) - break - end + print("Controller must scan chests...") + local nodeName = peripheral.getName(node) + local storageChests = {peripheral.find("inventory")} + for i,v in ipairs(storageChests) do + if peripheral.getName(v) == nodeName then + table.remove(storageChests, i) + break end - controller = Storage:fromPeripherals(Storage.assumeHomogeneous(storageChests)) - saveState(fname, controller) end + local controller = Storage:fromPeripherals(Storage.assumeHomogeneous(storageChests)) + saveState(fname, controller) return controller end