Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local modem = peripheral.find("modem", rednet.open);
- local logging = "Potion_Brewer_LOGGER"
- local errorName = "DISPENSER_CONTROLLER"
- -- different protocols used by this program
- local dispenserRequestProtocol = "Potion_Brewer_Dispenser_Request_v001"
- local dispenserNodeProtocol = "Potion_Brewer_Ingredient_Dispenser_Node_v001"
- local beltSelectorProtocol = "Potion_Brewer_BELT_SELECTOR"
- local scannerProtocol = "Potion_Brewer_SCANNER"
- local timeoutErrorProtocol = "Potion_Brewer_ERROR_PROTOCOL_TIMEOUT"
- -- different event names used by this program (lets just use protocols in future)
- local eventDispenseItem = "EVENT_DISPENSE_"
- local eventDispenseItemStarted = "EVENT_DISPENSE_STARTED_"
- local eventSelectBelt = "EVENT_BELT_SELECT_"
- local eventScanner = "EVENT_SCANNER_"
- local scannerDispenser = "dispenser"
- local timeoutTime = 10
- local error = false
- function log(string)
- print(string)
- rednet.broadcast("[" .. errorName .. "] " ..string, logging)
- end
- function dispenseItem(string)
- parallel.waitForAny(
- function()
- log("attempting to dispense " .. string)
- -- requrest that the item is dispensed
- rednet.broadcast(eventDispenseItem .. string, dispenserNodeProtocol)
- local message = ""
- local senderID = 0
- log("dispense request sent to nodes")
- -- wait for the response from the dispenser node
- while message ~= eventDispenseItemStarted .. string do
- senderID, message = rednet.receive(dispenserNodeProtocol)
- end
- log("response received")
- message = ""
- -- wait for the item to be detected on the conveyor
- while message ~= eventScanner .. scannerDispenser do
- senderID, message = rednet.receive(scannerProtocol)
- end
- log("item detected! dispense successful!")
- end,
- function()
- -- wait for timeout
- sleep(timeoutTime)
- log("Dispense Item Timeout! Took longer than " .. timeoutTime .. " seconds!")
- rednet.broadcast(errorName, timeoutErrorProtocol)
- error = true
- end)
- end
- dispenseItem("netherwart")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement