Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local oldRednet = rednet
- local oldSide = false
- -- shorter functions
- local net = rednet
- local brod = net.broadcast
- local pull = os.pullEvent
- function send(id, msg)
- net.send(id, msg)
- end
- function setMaster(ID)
- local save = fs.open(".master", "w")
- save.writeLine(tonumber(ID))
- save.close()
- end
- function getMaster()
- local save = fs.open(".master", "r")
- local cRead = save.readLine()
- save.close()
- return tonumber(cRead)
- end
- function setGlobalMessage(msg)
- local save = fs.open(".global", "w")
- save.writeLine(msg)
- save.close()
- end
- function getGlobalMessage()
- local save = fs.open(".global", "r")
- local cRead = save.readLine()
- save.close()
- return cRead
- end
- function open(side)
- oldSide = side
- rednet.open(side)
- end
- function close()
- rednet.close(oldSide)
- end
- function ping()
- setGlobalMessage(" ")
- brod("ping")
- local id, msg = rednet.receive(2)
- if msg == "pong" then
- setMaster(id)
- setGlobalMessage("Connected")
- end
- -- id, msg, dist = rednet.receive(2)
- -- print(msg)
- -- if msg == "pong" then
- -- setMaster(id)
- -- setGlobalMessage("success")
- -- end
- -- if not id then
- -- term.setTextColor(colors.red)
- -- print("Timeout")
- -- term.setTextColor(colors.white)
- -- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement