--Stairs Down Simple Script v1
--Turtle Program Computer Craft
--by SemlerPDX(July2016)
--COMMENT SYNTAX EXPLAINATION
--torches must be in slot 1 (one for every 3rd layer dug)
--stairs can be in slot 2 if desired, see below
--StairsDown 20 (number of stairs down) 1 (or blank -- 1 will add stairs from slot 2)
--example: StairsDown 20 (makes stairs 20 deep with torches but no stair blocks)
--example2: StairsDown 20 1 (makes stairs 20 deep w/ torches and stair blocks)
-- Variables --
local args = {...}
local d = args[1] or 0
local s = args[2] or 0
local r = 0 + d
local t = turtle
local lit = 2
-- F-ACK --
if #args ~= 2 then
print("<error420: syntax>")
print("<ex: Stairs 20 1 (starts digging stairs 20 blocks deep with stair blocks in slot 2)>")
return
end
if d == 0 then
print("<error421: missing length>")
print("<ex: Stairs 20 (starts digging stairs 20 blocks deep)>")
return
end
-- Functions --
--force forward function by CCCode
local function forceForward()
while not t.forward() do
t.dig()
end
end
--dig down, decrement lit variable
local function fDown()
t.digDown()
t.down()
lit = lit - 1
end
--shave 4 blocks and place torch if needed
local function fShave()
for v=1,4 do
if v == 3 then
if lit == 0 then
t.placeUp()
lit = lit + 2
forceForward()
else
forceForward()
end
else
forceForward()
end
end
end
--move to next shaving position
local function fReturn()
for v=1,3 do
t.back()
end
end
--place stairs while returning home
local function fHomeS()
t.turnLeft()
t.turnLeft()
t.select(2)
while r ~=0 do
t.place()
t.up()
t.forward()
r = r -1
end
end
--return home
local function fHome()
while r ~=0 do
t.up()
t.back()
r = r -1
end
end
--clear display screen
local function fset()
term.clear()
term.setCursorPos(1,1)
end
-- Pre-fire scripts --
fset()
print("Building staircase "..tostring(d).." blocks down...")
t.digDown()
t.down()
sleep(2)
---- Main Loop ----
while d ~= 0 do
local function fcancel()
local event, key = os.pullEvent("key")
end
local function fmain()
fShave()
fReturn()
fDown()
d = d - 1
end
FunctionEnabled = parallel.waitForAny(fcancel,fmain)
if FunctionEnabled == 1 then
textutils.slowPrint("Cancelling Build...", 15)
sleep(1.65)
break
end
end
-- Evaluate Ending --
if FunctionEnabled == 1 then --(1 = functions cancelled, 2 = standard function looped)
fset()
print("Build Cancelled by user")
print("...returning to start in 5 seconds - move out of path")
sleep(6)
fHome()
t.select(1)
else
fset()
print("Build Completed")
if s == 1 then
print("Building stairs and returning home...")
fHomeS()
t.select(1)
fset()
print("...program complete")
else
fset()
fHome()
t.select(1)
print("...program complete")
end
end
Comments