Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local args = {...}
- turtles = {}
- if #args ~= 1 then
- print("Please give me a name")
- error()
- end
- function getModemSide()
- sides = peripheral.getNames()
- for k, v in pairs(sides) do
- if peripheral.getType(v) == "modem" then return v end
- end
- return nil
- end
- function getMonitor()
- sides = peripheral.getNames()
- for k, v in pairs(sides) do
- if peripheral.getType(v) == "monitor" then return v end
- end
- return nil
- end
- function openRednet()
- side = getModemSide()
- if not side then
- error("Could not find modem")
- end
- rednet.open(side, 255)
- rednet.host("turtle_status", args[1])
- end
- function pushToMonitor()
- local monitor = getMonitor()
- if monitor then
- term.redirect(peripheral.wrap(monitor))
- end
- end
- function readRednet()
- while true do
- local id, message, protocol = rednet.receive()
- if message == "request_connect" then
- turtles[id] = {connected = true, status = "connected"}
- elseif type(message) == "table" then
- -- do later
- else
- if turtles[id] then
- turtles[id].status = message
- end
- end
- updateStatus()
- end
- end
- function updateStatus()
- pushToMonitor()
- term.clear()
- term.setCursorPos(1,1)
- print("-- Turtle Status --")
- for k,v in pairs(turtles or {}) do
- print(k..": ".. v.status)
- end
- end
- openRednet()
- readRednet()
Add Comment
Please, Sign In to add comment