Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Furnace control
- -- Setup:
- -- (from above)
- -- Comp - Outp
- -- Inpu - Furn
- -- the second computer under the furnace,
- -- and a wired modem connecting the 2 computers
- -- Computer 1: http://pastebin.com/06cjixf9
- -- Computer 2: (this one) http://pastebin.com/RjyREdT2
- -- Screenshots of setup:
- -- 1 http://i.imgur.com/t9GFE2r.png
- -- 2 http://i.imgur.com/WjnunBC.png
- local furnace = peripheral.wrap("top")
- or error("Unable to wrap furnace!",0)
- local modemside = "bottom"
- local modem
- if peripheral.getType(modemside) == "modem" then
- modem = peripheral.wrap(modemside)
- or error("Unable to wrap modem!",0)
- else error("No modem found, please correct!",0) end
- local function getAllStacks(inv)
- local t = {}
- local size = inv.getInventorySize()
- for slot = 1,size do
- local item = inv.getStackInSlot(slot) or {}
- item.rawName = item.rawName or ""
- item.qty = item.qty or 0
- item.dmg = item.dmg or 0
- item.name = item.name or ""
- item.id = item.id or 0
- t[slot] = item
- end
- return t
- end
- local function isEmpty()
- local items = getAllStacks(furnace)
- for slot,item in pairs(items) do
- if item.qty > 0 then
- return false
- end
- end
- return true
- end
- modem.open(1)
- print("Waits for control computer to ask if the furnace is empty.")
- while true do
- local ev,p1,p2,p3,p4,p5 = os.pullEvent()
- if ev == "modem_message" and p1 == modemside and p2 == 1 then
- local msg = textutils.unserialize(p4)
- if type(msg) == "table" then
- if msg.task == "furnace"
- and msg.value == "question" then
- local reply = textutils.serialize({task="furnace",value=isEmpty()})
- modem.transmit(1,1,reply)
- end
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement