Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function string:split(s, delimiter)
- local result = {};
- for match in (s .. delimiter):gmatch("(.-)" .. delimiter) do
- table.insert(result, match);
- end
- return result;
- end
- function getMsgData(msg)
- local i, j = string.find(msg, ":")
- local tag = string.sub(msg, 1, i - 1)
- local pts = string:split(string.sub(msg, i + 1, -1), ",")
- return tag, pts
- end
- --syslib end
- args = { ... }
- local rootId = tonumber(args[1])
- --to sys_service_printUnits
- local monitor = peripheral.wrap("left") --find("monitor")
- monitor.setTextScale(0.5)
- rednet.open("back")
- rednet.send(rootId, "@root:getUnitsData")
- local done = false
- while not done do
- local id, msg = rednet.receive()
- local i, j = string.find(msg, ":")
- if i ~= nil then
- local tag = string.sub(msg, 1, i - 1)
- local body = string.sub(msg, i + 1, -1)
- if tag == "action" then
- local pts = string:split(body, " ")
- print("" .. table.getn(pts))
- print("" .. body)
- monitor.clear()
- for i = 1, tonumber(table.getn(pts) / 3) do
- monitor.setCursorPos(1, i)
- monitor.write(pts[(i - 1) * 3 + 1] .. ": ")
- monitor.write(pts[(i - 1) * 3 + 2] .. " - ")
- monitor.write(pts[(i - 1) * 3 + 3])
- end
- sleep(1)
- rednet.send(rootId, "@root:getUnitsData")
- elseif tag == "@programs" then
- local tag, pts = getMsgData(msg)
- if pts[1] == "terminate" then
- done = true
- else print("unknown message: ", msg)
- end
- else
- print("unknown msg-tag: ", msg)
- end
- else print("unknown msg: ", msg)
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement