Advertisement
SemlerPDX

StairsDown-v1.2

Jul 8th, 2024 (edited)
18
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.68 KB | Gaming | 0 0
  1. --Stairs Down Simple Script v1
  2. --Turtle Program Computer Craft
  3. --by SemlerPDX(July2016)
  4.  
  5. --COMMENT SYNTAX EXPLAINATION
  6. --torches must be in slot 1 (one for every 3rd layer dug)
  7. --stairs can be in slot 2 (equal to or greater than number of stairs requested)
  8.  
  9. --StairsDown 20 (number of stairs down -- will use stairs from slot 2)
  10. --example: StairsDown 20 (makes stairs 20 deep w/ torches and stair blocks)
  11.  
  12.  
  13. -- Variables --
  14. local args = {...}
  15. local d = args[1] or 0
  16. local r = 0 + d
  17. local t = turtle
  18. local lit = 2
  19.  
  20. if d == 0 then
  21. print("<error421: missing length>")
  22. print("<ex: Stairs 20 (starts digging stairs 20 blocks deep with stair blocks in slot 2)>")
  23. return
  24. end
  25.  
  26. -- Functions --
  27. local function ForceForward()
  28. while not t.forward() do
  29. t.dig()
  30. end
  31. end
  32.  
  33. --dig down, decrement lit variable
  34. local function ForceDown()
  35. t.digDown()
  36. t.down()
  37. lit = lit - 1
  38. end
  39.  
  40. --shave 4 blocks and place torch if needed
  41. local function Shave()
  42. for v=1,4 do
  43. if v == 3 then
  44. if lit == 0 then
  45. t.placeUp()
  46. lit = lit + 2
  47. ForceForward()
  48. else
  49. ForceForward()
  50. end
  51. else
  52. ForceForward()
  53. end
  54. end
  55. end
  56.  
  57. --move to next shaving position
  58. local function ResetRun()
  59. for v=1,3 do
  60. t.back()
  61. end
  62. end
  63.  
  64. --place stairs while returning home
  65. local function StairsHome()
  66. t.turnLeft()
  67. t.turnLeft()
  68. t.select(2)
  69. while r ~=0 do
  70. t.place()
  71. t.up()
  72. t.forward()
  73. r = r -1
  74. end
  75. end
  76.  
  77. --return home
  78. local function ForceHome()
  79. while r ~=0 do
  80. t.up()
  81. t.back()
  82. r = r -1
  83. end
  84. end
  85.  
  86. --clear display screen
  87. local function ClearScr()
  88. term.clear()
  89. term.setCursorPos(1,1)
  90. end
  91.  
  92. -- Pre-fire scripts --
  93. ClearScr()
  94. print("Building staircase "..tostring(d).." blocks down...")
  95. t.digDown()
  96. t.down()
  97. sleep(2)
  98.  
  99. ---- Main Loop ----
  100. while d ~= 0 do
  101.  
  102. local function ForceCancel()
  103. local event, key = os.pullEvent("key")
  104. end
  105.  
  106. local function Main()
  107. Shave()
  108. ResetRun()
  109. ForceDown()
  110. d = d - 1
  111. end
  112.  
  113. FunctionEnabled = parallel.waitForAny(ForceCancel,Main)
  114.  
  115. if FunctionEnabled == 1 then
  116. textutils.slowPrint("Cancelling Build...", 15)
  117. sleep(1.65)
  118. break
  119. end
  120.  
  121. end
  122.  
  123. -- Evaluate Ending --
  124. if FunctionEnabled == 1 then --(1 = functions cancelled, 2 = standard function looped)
  125. ClearScr()
  126. print("Build Cancelled by user")
  127. print("...returning to start in 5 seconds - move out of path")
  128. sleep(6)
  129. ForceHome()
  130. t.select(1)
  131. else
  132. ClearScr()
  133. print("Build Completed")
  134. print("Building stairs and returning home...")
  135. t.up()
  136. StairsHome()
  137. t.select(1)
  138. --ClearScr()
  139. print("...program complete")
  140. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement