SoundChaos

safetyBridge

May 4th, 2020
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.42 KB | None | 0 0
  1. local tArgs = { ... }
  2.  
  3. if #tArgs ~= 1 then
  4. print( "Usage: bridge <length>" )
  5. return
  6. end
  7.  
  8. -- Initial Fueling
  9. turtle.refuel(1)
  10.  
  11. -- variable to tell main function when to stop
  12. local o = 1
  13.  
  14. -- Function to get the fuel level of the robot as a number
  15. fcount = function()
  16. return turtle.getFuelLevel()
  17. end
  18.  
  19. -- Move forward, Fuel Check and Refuel function
  20. forwardCheck = function()
  21. turtle.forward()
  22.  
  23. if fcount() < 1 then
  24. turtle.select(1)
  25. print ("Attempting to eat my fuel...")
  26. if turtle.getItemCount(1) < 1 then
  27. print ("I am out of fuel...")
  28. o = 0
  29. end
  30. turtle.refuel(1)
  31. turtle.select(2)
  32. end
  33. end
  34.  
  35. buildBridge = function(length)
  36. local i = 0
  37. while i < length do
  38. placeBlocks()
  39. while turtle.detect() do
  40. turtle.attack()
  41. turtle.attackUp()
  42. turtle.dig()
  43. end
  44. forwardCheck()
  45. i = i + 1
  46. end
  47. turtle.turnRight()
  48. turtle.turnRight()
  49. for i=1,length do
  50. turtle.forward()
  51. end
  52. end
  53.  
  54. placeBlocks = function()
  55. if not turtle.detectDown() then
  56. turtle.select(2)
  57. turtle.placeDown()
  58. end
  59. turtle.turnLeft()
  60. if not turtle.detect() then
  61. turtle.select(2)
  62. turtle.place()
  63. end
  64. turtle.turnRight()
  65. turtle.turnRight()
  66. if not turtle.detect() then
  67. turtle.select(2)
  68. turtle.place()
  69. end
  70. turtle.turnLeft()
  71. end
  72.  
  73. buildBridge(tonumber(tArgs[1]))
Advertisement
Add Comment
Please, Sign In to add comment