Dr_Turtle

Untitled

Jun 28th, 2021 (edited)
31
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.83 KB | None | 0 0
  1. args = {...}
  2. gridX = (tonumber(args[1])*9)
  3. gridY = (tonumber(args[1])*9)
  4. posX = 1
  5. posY = 1
  6. facing = 0
  7. cycles = 0
  8.  
  9.  
  10. function rotate(direction)
  11. if direction == "R" then
  12. turtle.turnRight()
  13. facing=facing+1
  14. elseif direction == "L" then
  15. turtle.turnLeft()
  16. facing = facing-1
  17. elseif direction == "180" then
  18. facing = facing+2
  19. end
  20. if facing>3 then
  21. facing=facing-4
  22. elseif facing<0 then
  23. facing=facing+4
  24. end
  25. end
  26.  
  27. function move(blocks)
  28. for j = 1,blocks do
  29. turtle.forward()
  30. if facing == 0 then
  31. posY=posY+1
  32. elseif facing == 1 then
  33. posX=posX+1
  34. elseif facing == 2 then
  35. posY=posY-1
  36. elseif facing == 3 then
  37. posX=posX+1
  38. end
  39. if math.fmod(posY,5)==3 and (facing==0 or facing==2) then
  40. turtle.placeDown()
  41. elseif (posY==gridY or posY==1) and (facing==0 or facing==2) then
  42. turtle.placeDown()
  43. end
  44. if ((posY==gridY or posY==1) and (facing==0 or facing==2)) or ((posX==gridX or posx==1) and (facing==1 or facing==3)) then print("break")
  45. break end
  46. end
  47. end
  48.  
  49. function nextColumn()
  50. if facing==0 then
  51. rotate("R")
  52. move(5)
  53. rotate("R")
  54. elseif facing==2 then
  55. rotate("L")
  56. move(5)
  57. rotate("L")
  58. end
  59. end
  60.  
  61. function main()
  62. turtle.select(1)
  63. rotate("R")
  64. move(2)
  65. rotate("L")
  66. for i = 1,math.floor(gridX/5) do
  67. move(gridY)
  68. nextColumn()
  69. end
  70. move(gridY)
  71. if gridX>(posX+2) then
  72. nextColumn()
  73. move(gridY)
  74. end
  75. if facing==0 then
  76. rotate("L")
  77. move(gridX-1)
  78. rotate("L")
  79. move(gridY-1)
  80. rotate("180")
  81. elseif facing==2 then
  82. rotate("R")
  83. move(gridX-1)
  84. rotate("R")
  85. end
  86. end
  87.  
  88. local trigger = true;
  89. while true do
  90. os.pullEvent("redstone")
  91. if rs.getInput("back") and trigger then
  92. cycles=cycles+1
  93. if cycles==2 then
  94. main()
  95. cycles=0
  96. trigger=false
  97. end
  98. elseif not rs.getInput("back") then
  99. trigger = true
  100. end
  101. end
  102.  
  103.  
Add Comment
Please, Sign In to add comment