diff --git a/compost_control.lua b/compost_control.lua index dc9b63f..cb700cb 100644 --- a/compost_control.lua +++ b/compost_control.lua @@ -7,7 +7,9 @@ local SOURCES = { "" } -local COMPOST_INV = "" +local COMPOST_INPUT = "" +local COMPOST_OUTPUT = "" +local STORAGE = "" local SLEEP_TIME = 40 @@ -27,17 +29,18 @@ function compare_counts (count1, count2) diffs[item] = count - count2[item] end end + return diffs end function compost (src, item_name, amount) - if amount < 1 return end + if amount < 1 then return end local amount_moved = 0 -- 1. scan through inventory until {item} is found - for slot, item in pairs(src.list()) + for slot, item in pairs(peripheral.call(src, "list")) do if item.name == item_name then -- 2. move up to {amount} to compost, recording amount moved amount_moved = peripheral.call( - COMPOST_INV, "pullItems", src, slot, amount + COMPOST_INPUT, "pullItems", src, slot, amount ) break end @@ -46,7 +49,14 @@ function compost (src, item_name, amount) return compost(src, item_name, amount - amount_moved) end +function move_all (src, dest) + for slot, item in pairs(peripheral.call(src, "list")) do + peripheral.call(src, "pushItems", dest, slot) + end +end + while true do + move_all(COMPOST_OUTPUT, STORAGE) for _, source in ipairs(SOURCES) do local totals = tally_up(source) local diffs = compare_counts(totals, CHECKS)