jseely

turtle

Nov 17th, 2012
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.23 KB | None | 0 0
  1. module(...)
  2.  
  3. local Utils = require "utils"
  4.  
  5. function turn(dir, times)
  6. times = times or 1
  7. for i = 1, times, 1 do
  8. if dir == "right" then
  9. turtle.turnRight()
  10. elseif dir == "left" then
  11. turtle.turnLeft()
  12. end
  13. end
  14. end
  15.  
  16. function swapRowDir(currentDir)
  17. if currentDir == "right" then
  18. return "left"
  19. elseif currentDir == "left" then
  20. return "right"
  21. end
  22. end
  23.  
  24. function swapColDir(currentDir)
  25. if currentDir == "up" then
  26. return "down"
  27. elseif currentDir == "down" then
  28. return "up"
  29. end
  30. end
  31.  
  32. function sForward(times)
  33. times = times or 1
  34. for i = 1, times, 1 do
  35. if not turtle.forward() then
  36. if times == 1 then
  37. return false
  38. end
  39. return i - 1
  40. end
  41. end
  42. if times == 1 then
  43. return true
  44. end
  45. return times
  46. end
  47.  
  48. function sUp(times)
  49. times = times or 1
  50. for i = 1, times, 1 do
  51. if not turtle.up() then
  52. if times == 1 then
  53. return false
  54. end
  55. return i - 1
  56. end
  57. end
  58. if times == 1 then
  59. return true
  60. end
  61. return times
  62. end
  63.  
  64. function sDown(times)
  65. times = times or 1
  66. for i = 1, times, 1 do
  67. if not turtle.down() then
  68. if times == 1 then
  69. return false
  70. end
  71. return i - 1
  72. end
  73. end
  74. if times == 1 then
  75. return true
  76. end
  77. return times
  78. end
Advertisement
Add Comment
Please, Sign In to add comment