Advertisement
zebillem

Basic Turtle controller

Nov 1st, 2014
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.36 KB | None | 0 0
  1. function readData()
  2. local h=fs.open("houseData","r")
  3. data = h.readLine()
  4. action = {}
  5. for i=1,string.len(data),2 do
  6. command=string.sub(data,i,i)
  7. times=tonumber(string.sub(data,i+1,i+1))
  8. table.insert(action,{command,times})
  9. end
  10. end
  11.  
  12. function chooseSlot(givenSlot)
  13. local chosenSlot = givenSlot
  14. for i=5,16 do
  15. turtle.select(i)
  16. if turtle.compareTo(givenSlot) then
  17. chosenSlot = i
  18. end
  19. turtle.select(chosenSlot)
  20. end
  21. end
  22.  
  23. function placeBehind(times)
  24. for i = 1,times do
  25. turtle.forward()
  26. turtle.turnRight()
  27. turtle.turnRight()
  28. turtle.place()
  29. turtle.turnRight()
  30. turtle.turnRight()
  31. end
  32. end
  33.  
  34. function moveForward(times)
  35. for i=1,times do
  36. turtle.forward()
  37. end
  38. end
  39.  
  40. function doAction(command,times)
  41. if command =="p" then
  42. chooseSlot(times)
  43. placeBehind(1)
  44. elseif command =="f" then
  45. moveForward(times)
  46. elseif command =="b" then
  47. placeBehind(times)
  48. elseif command =="d" then
  49. turtle.turnRight()
  50. moveForward(times)
  51. elseif command =="a" then
  52. turtle.turnLeft()
  53. moveForward(times)
  54. elseif command =="s" then
  55. turtle.turnRight()
  56. turtle.turnRight()
  57. moveForward(times)
  58. end
  59. end
  60.  
  61. readData()
  62. for i=1,#action do
  63. doAction(action[i][1],action[i][2])
  64. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement