mdc_tjc

test

Apr 7th, 2015
473
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.51 KB | None | 0 0
  1. --Pastebin name: tUFHwJn3
  2. --Position this device in the branch tunnel
  3.  
  4. local tArgs = { ... } -- obtain tunnel length and turn around options
  5. if #tArgs ~= 2 then
  6.     print( "Usage: tunnel <length>, and then turn around: <y> or <n>" )
  7.     return
  8.     end
  9.  
  10. local length = tonumber( tArgs[1] ) -- Check if the tunnel length is > 1
  11. if length < 1 then
  12.     print( "Tunnel length must be positive" )
  13.     return
  14.     end
  15.  
  16. local turn = ( tArgs[2] ) -- Check if the turtle turn around option is y or n
  17. if not( turn ~= ( "y" ) or turn ~= ( "n" )) then
  18.     print( "Indicate whether to have the turtle go down to the next course and turn around" )
  19.     return
  20.     end
  21.  
  22. local fuel = turtle.getFuelLevel()
  23. if fuel < 80 then
  24.     print("you must add more fuel")
  25.     return
  26.     end
  27.  
  28. --definition of functions follows
  29.  
  30. local function tryDig() -- This function digs forward one block
  31.     while turtle.detect() do
  32.         if turtle.dig() then
  33.             sleep(0.5)
  34.         else
  35.             return false
  36.         end
  37.     end
  38.     return true
  39.     end
  40.  
  41. local function tryDigUp() -- This function digs up one block
  42.     while turtle.detectUp() do
  43.         if turtle.digUp() then
  44.             sleep(0.5)
  45.         else
  46.             return false
  47.         end
  48.     end
  49.     return true
  50. end
  51.  
  52. local function tryDigDown() -- This function digs down one block
  53.     while turtle.detectDown() do
  54.         if turtle.digUp() then
  55.             sleep(0.5)
  56.         else
  57.             return false
  58.         end
  59.     end
  60.     return true
  61. end
Advertisement
Add Comment
Please, Sign In to add comment