Advertisement
Guest User

Bridge

a guest
Sep 26th, 2014
1,045
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.19 KB | None | 0 0
  1. -- Programmed:  17 May 2014
  2. -- by Skyler James
  3. --
  4. -- Builds a bridge <length>
  5. -- blocks long, 1 block wide
  6. --
  7. -- The blocks to be used in
  8. -- the bridge MUST be placed
  9. -- in slot 9. There is error
  10. -- checking to ensure this.
  11. --
  12. -- Turtle will NOT break any
  13. -- blocks in its way
  14.  
  15. local tArgs = { ... }
  16. if #tArgs ~= 1 then
  17.     print( "Usage: bridge <length>" )
  18.     return
  19. end
  20.  
  21. -- Set length with user input
  22. local length = tonumber( tArgs[1] )
  23. if length < 1 then
  24.     print( "Bridge length must be positive" )
  25.     return
  26. end
  27.  
  28. -- Check that there are <length>
  29. -- blocks provided in slot 9
  30. local numblocks = turtle.getItemCount(9)
  31. if numblocks < length
  32.     print("Please place at least "..length.." building blocks in slot 9")
  33.     return
  34. end
  35.  
  36. -- Place a block underneath
  37. -- the turtle to build bridge
  38. function putblockdown()
  39.     if not (turtle.detectDown()) then
  40.         turtle.select(9)
  41.         turtle.placeDown()
  42.     end
  43. end
  44.  
  45. -- Move forward <length> times
  46. -- and build a bridge with
  47. -- blocks provided in slot 9
  48. local i = 0
  49. for i,length,1 do
  50.     if (turtle.detect()) then
  51.         break
  52.     else
  53.         putblockdown()
  54.         turtle.forward()
  55.     end
  56. end
  57.  
  58. -- That's all, folks!
  59. print("Built a bridge "..i.." blocks long")
  60. return
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement