Advertisement
melzneni

sys_service_printUnits

Feb 9th, 2020
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.75 KB | None | 0 0
  1. function string:split(s, delimiter)
  2. local result = {};
  3. for match in (s .. delimiter):gmatch("(.-)" .. delimiter) do
  4. table.insert(result, match);
  5. end
  6. return result;
  7. end
  8.  
  9. function getMsgData(msg)
  10. local i, j = string.find(msg, ":")
  11. local tag = string.sub(msg, 1, i - 1)
  12. local pts = string:split(string.sub(msg, i + 1, -1), ",")
  13. return tag, pts
  14. end
  15.  
  16. --syslib end
  17.  
  18. args = { ... }
  19. local rootId = tonumber(args[1])
  20. --to sys_service_printUnits
  21. local monitor = peripheral.wrap("left") --find("monitor")
  22. monitor.setTextScale(0.5)
  23. rednet.open("back")
  24. rednet.send(rootId, "@root:getUnitsData")
  25. local done = false
  26. while not done do
  27. local id, msg = rednet.receive()
  28. local i, j = string.find(msg, ":")
  29. if i ~= nil then
  30. local tag = string.sub(msg, 1, i - 1)
  31. local body = string.sub(msg, i + 1, -1)
  32. if tag == "action" then
  33. local pts = string:split(body, " ")
  34. print("" .. table.getn(pts))
  35. print("" .. body)
  36. monitor.clear()
  37. for i = 1, tonumber(table.getn(pts) / 3) do
  38. monitor.setCursorPos(1, i)
  39. monitor.write(pts[(i - 1) * 3 + 1] .. ": ")
  40. monitor.write(pts[(i - 1) * 3 + 2] .. " - ")
  41. monitor.write(pts[(i - 1) * 3 + 3])
  42. end
  43. sleep(1)
  44. rednet.send(rootId, "@root:getUnitsData")
  45. elseif tag == "@programs" then
  46. local tag, pts = getMsgData(msg)
  47. if pts[1] == "terminate" then
  48. done = true
  49. else print("unknown message: ", msg)
  50. end
  51. else
  52. print("unknown msg-tag: ", msg)
  53. end
  54. else print("unknown msg: ", msg)
  55. end
  56. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement