Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local modem = peripheral.find("modem", rednet.open);
- local idFilename = "id"
- local protocol = "Potion_Brewer_BELT_SELECTOR"
- local logging = "Potion_Brewer_LOGGER"
- local id = ""
- function log(string)
- print(string)
- rednet.broadcast("[BELT_SELECTOR_"..id.."] "..string, logging)
- end
- function init()
- -- get this selectors id
- local idFile = fs.open(idFilename, "r")
- if idFile then
- id = idFile.readAll()
- idFile.close()
- else
- log("failed to open id file: "..idFilename)
- end
- log("ID file loaded, this selector is: "..id)
- rednet.host(protocol, id)
- --wait for an event to dispense the item
- while true do
- --receive messages
- local senderID, message = rednet.receive(protocol)
- print(message)
- local eventName = "EVENT_BELT_SELECT_"..id
- if string.find(message, eventName) then
- --get the setting value
- log("attemting to set belt selection")
- local setting = string.sub(message, #eventName + 1, #message)
- setting = tonumber(setting)
- -- select the belt
- rs.setAnalogOutput("back", setting)
- --respond with a dispense started event
- rednet.broadcast("EVENT_BELT_SELECT_FINNISHED_" .. id .. " " .. setting, protocol)
- log("selected belt: " .. setting)
- end
- end
- end
- init()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement