Advertisement
Dission

place

Apr 3rd, 2020
665
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.09 KB | None | 0 0
  1. dir, depth, width = ...
  2. if dir == nil then
  3.     dir = 'down'
  4. end
  5. if depth == nil then
  6.     depth = 2
  7. end
  8. if width == nil then
  9.     width = 2
  10. end
  11.  
  12. num_moves = depth*width
  13. width_dir = 'right'
  14. height_dir = 'up'
  15. turn_again = false
  16. switch_height_dir = false
  17.  
  18. function place()
  19.     for i = 2, num_moves do
  20.         print('forward')
  21.         turtle.forward()
  22.         if turn_again == true then
  23.             if dir == 'down' or dir == 'up' then
  24.                 if width_dir == 'right' then
  25.                     turtle.turnRight()
  26.                     width_dir = 'left'
  27.                 elseif width_dir == 'left' then
  28.                     turtle.turnLeft()
  29.                     width_dir = 'right'
  30.                 end
  31.             end
  32.             turn_again = false
  33.         end
  34.         if i % depth == 0 then
  35.             if dir == 'down' or dir == 'up' then
  36.                 if width_dir == 'right' then
  37.                     turtle.turnRight()
  38.                 elseif width_dir == 'left' then
  39.                     turtle.turnLeft()
  40.                 end
  41.                 turn_again = true
  42.             end
  43.         end
  44.     end
  45. end
  46.  
  47. function init()
  48.     if dir == 'down' then -- start at ground level
  49.         turtle.up()
  50.         turtle.placeDown()
  51.     elseif dir == 'up' then -- start from ceiling height level
  52.         -- turtle.down()
  53.         turtle.placeUp()
  54.     place()
  55. end
  56.  
  57. init()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement