Advertisement
Guest User

turtle-control

a guest
Aug 9th, 2012
38
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.54 KB | None | 0 0
  1. rednet.open("top")
  2. turtleID = 111
  3. up = " "
  4. front = " "
  5. down = " "
  6. actions = {}
  7. start = 1
  8. while true do
  9. term.clear()
  10. for i = 1, #actions do
  11. print(actions[i])
  12. end
  13. term.setCursorPos(1,1)
  14. term.clearLine()
  15. print("Turtle mission control")
  16. term.setCursorPos(1,2)
  17. term.clearLine()
  18. print(" ")
  19. term.setCursorPos(1,3)
  20. term.clearLine()
  21. print(up)
  22. term.setCursorPos(1,4)
  23. term.clearLine()
  24. print(front)
  25. term.setCursorPos(1,5)
  26. term.clearLine()
  27. print(down)
  28. term.setCursorPos(1,6)
  29. term.clearLine()
  30. print(" ")
  31.  
  32. while true do
  33. event, key = os.pullEvent("key")
  34. if key == keys.w then
  35.     action = "forward"
  36.     redent.send(turtleID, "r = turtle.forward()")
  37.     break
  38. elseif key == keys.a then
  39.     action = "left"
  40.     redent.send(turtleID, "r = turtle.turnLeft()")
  41.     break
  42. elseif key == keys.s then
  43.     action = "back"
  44.     redent.send(turtleID, "r = turtle.back()")
  45.     break
  46. elseif key == keys.d then
  47.     action = "right"
  48.     redent.send(turtleID, "r = turtle.turnRight()")
  49.     break
  50. elseif key == 42 then
  51.     action = "down"
  52.     redent.send(turtleID, "r = turtle.down()")
  53.     break
  54. elseif key == 57 then
  55.     action = "up"
  56.     redent.send(turtleID, "r = turtle.up()")
  57.     break
  58. elseif key == 28 then
  59.     action = "dig"
  60.     redent.send(turtleID, "r = turtle.dig()")
  61.     break
  62. end
  63. end
  64. startClock = os.clock()
  65. success = false
  66. while os.clock - startClock < 3 do
  67. id, msg = rednet.receive(1)
  68. if id == turtleID then
  69.     success = true
  70.     break
  71. end
  72. end
  73. if not success then error("Connection lost!") end
  74. r, front, up, down = textutils.unserialize(msg)
  75. if r then
  76.     table.insert(actions, acac)
  77. end
  78. end
  79. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement