This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
PyromancerVx's profile picture

[Lua][Error] Problem with code

Started by PyromancerVx, 21 April 2012 - 09:21 AM
PyromancerVx #1
Posted 21 April 2012 - 11:21 AM

function MineTunnel()
print("Enter the length of the tunnel: ")
local a = io.read()
print("Name the tunnel: ")
local  name = io.read()
a = tonumber(a)
local b = 0
while true do
turtle.digUp()
turtle.digDown()
turtle.down()
if turtle.detectDown() == false then
turtle.select(1)
turtle.placeDown()
else
end
turtle.up()
while true do
if turtle.detect(true) then
turtle.dig()
sleep(1)
else
break
end
end
turtle.forward()
b = b+1
if b >= a then
print("Tunnel "..name.." mined!")
rednet.open("right")
rednet.broadcast("ended mining tunnel "..name..".")
rednet.close("right")
break
else
end
end
end

I copied this code from my API text. Wrote it myself with the help of some tutorials and stuff :)/>/>. Everything is working EXCEPT the turtle wont place stuff when there is nothing under it when it is checking. I tried everything I know of but cant get it to work so im asking your help on this one.
Luanub #2
Posted 21 April 2012 - 01:09 PM
The code works fine when I run. Everything looks good too. No typo's, proper syntax, with the exception of a couple of extra else's. But even with those it should work.

You don't need to do


else
end


you can just do

if 123 == abc then
do stuff
end
OminousPenguin #3
Posted 21 April 2012 - 06:24 PM
Works for me. Won't work at the bottom of the world on the admin layer. Just wondering if you're testing on a superflat.

Maybe it would be a good idea to check the sides and top as well? There might be lava or water spilling into the tunnel.
PyromancerVx #4
Posted 22 April 2012 - 06:08 AM
um what is the admin layer? I was testing in a normal world but near bedrock.
OminousPenguin #5
Posted 22 April 2012 - 12:44 PM
Turtle can't place blocks on level 0. I doubt you were that low… there's normally bedrock blocks on 2 and 3 as well.
Luanub #6
Posted 22 April 2012 - 01:20 PM
0-4 can have bedrock and are considered the "admin layer" if I remember correctly. You would have to be pretty deep for that to be the issue. Have you tried it anywhere else?
PyromancerVx #7
Posted 22 April 2012 - 01:42 PM
I think I tested it on ground level too. Didn't work
libraryaddict #8
Posted 22 April 2012 - 01:59 PM
This is working fine for me as well.

You can use
if not turtle.detectDown() then
instead of
if turtle.detectDown() == false then