Posted 25 December 2012 - 03:24 AM
i made (took and changed) some code, it makes a 3x3 tunnel.
i want to have it return to the begining, but it doesnt return, it just stays is spot (does turn, but turns back)
also i want to add a torch placeing thingy but not sure how/what the code is
also im a noob at this (i just started today) if something seems obvious for you, its not for me
my code:
i want to have it return to the begining, but it doesnt return, it just stays is spot (does turn, but turns back)
also i want to add a torch placeing thingy but not sure how/what the code is
also im a noob at this (i just started today) if something seems obvious for you, its not for me
my code:
local tArgs = { ... }
if #tArgs ~= 1 then
print( "Usage: tunnel <length>" )
return
end
local length = tonumber( tArgs[1] )
if length < 1 then
print( "Tunnel length must be positive" )
return
end
local depth = 0
local collected = 0
local function collect()
collected = collected + 1
if math.fmod(collected, 25) == 0 then
print( "Mined "..collected.." blocks." )
end
end
local function tryDig()
while turtle.dig() do
collect()
sleep(0.5)
if not turtle.detect() then
return true
end
end
return not turtle.detect()
end
local function tryDigUp()
while turtle.digUp() do
collect()
sleep(0.5)
if not turtle.detectUp() then
return true
end
end
return not turtle.detectUp()
end
print( "Tunnelling..." )
for n=1,length do
tryDigUp()
turtle.turnLeft()
tryDig()
turtle.up()
tryDig()
tryDigUp()
turtle.up()
tryDig()
turtle.turnRight()
turtle.turnRight()
tryDig()
turtle.down()
tryDig()
turtle.down()
tryDig()
turtle.turnLeft()
if n<length then
tryDig()
if not turtle.forward() then
print( "Aborting Tunnel." )
break
end
else
print( "Tunnel complete." )
end
end
print( "Returning to start..." )
turtle.turnLeft()
turtle.turnLeft()
while depth > 0 do
if turtle.forward() then
depth = depth - 1
else
turtle.dig()
end
end
turtle.turnRight()
turtle.turnRight()
print( "Tunnel complete." )
print( "Mined "..collected.." blocks total." )