ryanv09

flat

Sep 20th, 2012
3,115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.31 KB | None | 0 0
  1. -- 'flat' for turtles
  2. -- Made by ryanv09
  3.  
  4. -- Place the turtle at southwest corner of desired surface
  5.  
  6. arg = {...}
  7.  
  8. length = arg[1]
  9. width = arg[2]
  10.  
  11.  
  12. -- Change this value to reflect how many total slots the turtle has
  13. -- This is the slot that is checked for empty()
  14. slots = 16
  15.  
  16.  
  17. -- Usage
  18. if (length == nil or width == nil) then
  19.   print ("Usage: flat <length> <width>")
  20.   return
  21. end
  22.  
  23.  
  24. -- Checks if the turtle is empty
  25. -- If empty, pauses turtle until last slot has resources
  26. function empty()
  27.   if (turtle.getItemCount(slots) == 0) then
  28.     print(string.format("I am empty. Please load more materials in slot %d to continue.", slots))
  29.     while (turtle.getItemCount(slots) == 0) do
  30.       sleep(1)
  31.     end  
  32.   end
  33. end
  34.  
  35.  
  36. for i=0,(width - 1),1 do
  37.  
  38.   for j=1,(length - 1),1 do
  39.     empty()
  40.     turtle.forward()
  41.     turtle.placeDown()
  42.   end
  43.  
  44.  
  45.   if (i % 2 == 0) then
  46.    
  47.     if (i ~= width - 1) then
  48.       turtle.turnRight()
  49.       turtle.forward()
  50.       turtle.turnRight()
  51.       empty()  
  52.       turtle.placeDown()
  53.     end
  54.   else  
  55.     if (i ~= width - 1) then
  56.       turtle.turnLeft()
  57.       turtle.forward()
  58.       turtle.turnLeft()
  59.       empty()
  60.       turtle.placeDown()
  61.     end
  62.   end
  63.  
  64.   if (j ~= length - 1) then
  65.     empty()
  66.     turtle.placeDown()
  67.   end
  68. end
  69.  
  70. print("\nSurface complete.")
Advertisement
Add Comment
Please, Sign In to add comment