Advertisement
SemlerPDX

Tunnel

Aug 3rd, 2021 (edited)
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. --Tunnel Simple Script v1
  2. --Turtle Program Computer Craft
  3. --by SemlerPDX(July2021)
  4.  
  5. --pastebin get CJ5iY7G0 Tunnel
  6.  
  7. --COMMENT SYNTAX EXPLAINATION
  8. --torches must be in slot 1 (one for every 8th block, 2nd row high)
  9.  
  10. --Tunnel 20 (length in increments of 10)
  11. --example:  Tunnel 20 (makes tunnel 20 deep with torches)
  12.  
  13.  
  14. -- Variables --
  15. local args = {...}
  16. local d = args[1] or 0
  17. local r = 0 + d
  18. local t = turtle
  19.  
  20. -- F-ACK --
  21. if #args ~= 1 then
  22.   print("<error420: syntax>")
  23.   print("<ex: Tunnel 20 (starts digging tunnel 20 blocks deep)>")
  24.   return
  25. end
  26.  
  27. if d == 0 then
  28.   print("<error421: missing length>")
  29.   print("<ex: Tunnel 20 (starts digging tunnel 20 blocks deep)>")
  30.   return
  31. end
  32.  
  33. -- Functions --
  34. --force forward function by CCCode
  35. local function forceForward()
  36.   while not t.forward() do
  37.     t.dig()
  38.   end
  39. end
  40.  
  41. --dig down, decrement lit variable
  42. local function fDown()
  43.   t.digDown()
  44.   t.down()
  45. end
  46.  
  47. --dig up, turn around
  48. local function fUp()
  49.   t.digUp()
  50.   t.up()
  51. end
  52.  
  53. local function fRow()
  54.   fUp()
  55.   fUp()
  56.   for v=1,3 do
  57.     for s=1,10 do
  58.       if v == 3 and s == 5 then
  59.         t.placeUp()
  60.       end
  61.       forceForward()
  62.     end
  63.     if v ~= 3 then
  64.       t.turnLeft()
  65.       t.turnLeft()
  66.       fDown()
  67.     end
  68.   end
  69. end
  70.  
  71. --return home
  72. local function fHome()
  73.   t.turnLeft()
  74.   t.turnLeft()
  75.   while r ~=0 do
  76.     forceForward()
  77.     r = r -1
  78.   end
  79. end
  80.  
  81. --clear display screen
  82. local function fset()
  83.   term.clear()
  84.   term.setCursorPos(1,1)
  85. end
  86.  
  87. -- Pre-fire scripts --
  88. fset()
  89. print("Beginning Tunnel "..tostring(d).." blocks long...")
  90. --t.up()
  91. --t.down()
  92. sleep(2)
  93.  
  94. ---- Main Loop ----
  95. while d ~= 0 do
  96.  
  97.   local function fcancel()
  98.     local event, key = os.pullEvent("key")
  99.   end
  100.  
  101.   local function fmain()
  102.     fRow()
  103.     d = d - 10
  104.   end
  105.  
  106.   FunctionEnabled = parallel.waitForAny(fcancel,fmain)
  107.  
  108.   if FunctionEnabled == 1 then
  109.     textutils.slowPrint("Cancelling Tunnel...", 15)
  110.     sleep(1.65)
  111.     break
  112.   end
  113.  
  114. end
  115.  
  116. -- Evaluate Ending --
  117. if FunctionEnabled == 1 then    --(1 = functions cancelled, 2 = standard function looped)
  118.   fset()
  119.   print("Tunnel Cancelled by user")
  120. else
  121.   fset()
  122.   print("Tunnel Completed")
  123.   print("Returning home...")
  124.   fHome()
  125.   t.select(1)
  126.   fset()
  127.   print("...program complete")
  128. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement