Advertisement
problemlow

Tree Planter

May 19th, 2024 (edited)
994
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.67 KB | None | 0 0
  1. print("Spacing between sapplings?")
  2. spacing = tonumber(read())
  3. print("Enter grid size")
  4. gridSize = tonumber(read())
  5. slot = 1
  6. direction = 0
  7. placed = 0
  8. switchNum = 64
  9. function plant()
  10.     down = true
  11.     ups = -1
  12.     while down == true do
  13.         down = turtle.down()
  14.         ups = ups+1
  15.     end
  16.     turtle.up()
  17.     turtle.select(slot)
  18.     if placed > switchNum then
  19.         slot = slot+1
  20.         turtle.select(slot)
  21.         switchNum = placed+63
  22.     end
  23.     turtle.placeDown()
  24.     placed = placed+1
  25.     while ups > 1 do
  26.         turtle.up()
  27.         ups = ups-1
  28.     end
  29. end
  30.  
  31. function line()
  32.     lineLength = gridSize
  33.     while lineLength > 0 do
  34.         moveX = spacing
  35.         while moveX > 0 do
  36.             turtle.forward()
  37.             moveX = moveX-1
  38.         end
  39.         plant()
  40.         lineLength = lineLength-1
  41.     end
  42. end
  43.  
  44. function level()
  45.     desiredLines = gridSize
  46.     while desiredLines > 0 do
  47.         if direction == 0 then
  48.             plant()
  49.             line()
  50.             moveX = spacing
  51.             turtle.turnRight()
  52.             while moveX > 0 do
  53.                 turtle.forward()
  54.                 moveX = moveX-1
  55.             end
  56.             turtle.turnRight()
  57.             direction = 1
  58.             desiredLines = desiredLines-1
  59.         end
  60.        
  61.         if direction == 1 then
  62.             plant()
  63.             line()
  64.             moveX = spacing
  65.             turtle.turnLeft()
  66.             while moveX > 0 do
  67.                 turtle.forward()
  68.                 moveX = moveX-1
  69.             end
  70.             turtle.turnLeft()
  71.             direction = 0
  72.             desiredLines = desiredLines-1
  73.         end
  74.     end
  75. end
  76.  
  77.  
  78. level()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement