jBlume

Computer read message

Feb 17th, 2019
288
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.31 KB | None | 0 0
  1. local myid = os.computerID()
  2. local turtlelist = { 0, 5, 6 } -- Enter the ID of all your Mining Turtles Here --
  3. local turtlename = { "DIGGE01", "DIGGE02", "DIGGE03" } -- Enter the Name/ Label you have given your turtle here --
  4.  
  5. mon=peripheral.wrap("left")
  6. print("Turtle Monitor Terminal")
  7. rednet.open("top") -- Edit to what ever side you modem is on --
  8.  
  9.  
  10. print("Computer id for Monitor Terminal is "..tostring(myid))
  11.  
  12. function findIndexForId(id)
  13. for i,v in ipairs(turtlelist) do
  14. if id == v then
  15. return i
  16. end
  17. end
  18. return 0
  19. end
  20.  
  21. function checkTurtleForName(id,tlabel)
  22. local i = findIndexForId(id)
  23. if i == 0 then
  24. return -1
  25. end
  26. if turtlename == tlabel then
  27. return 1
  28. else
  29. return 0
  30. end
  31. end
  32.  
  33. local isValid = 0
  34.  
  35. while true do
  36. local timeString = textutils.formatTime(os.time(),false)
  37. senderId, message, distance = rednet.receive()
  38. isValid = checkTurtleForName(senderId, message)
  39.  
  40. if isValid == -1 then
  41. print("A Turtle"..senderId.." sent us a request but is not in our list")
  42. elseif isValid == 1 then
  43. rednet.send(senderId, "Valid")
  44. mon.scroll(1)
  45. mon.setCursorPos(1,5)
  46. mon.write("Mining Complete: "..senderId.." "..message.." at "..timeString)
  47. else
  48. rednet.send(senderId, "Not Valid")
  49. mon.scroll(1)
  50. mon.setCursorPos(1,5)
  51. mon.write("Error from "..senderId.." "..message.." at "..timeString)
  52. end
  53. end
Add Comment
Please, Sign In to add comment