Jump to content




[Lua][Error] Problem with code


  • You cannot reply to this topic
7 replies to this topic

#1 PyromancerVx

  • Members
  • 8 posts

Posted 21 April 2012 - 10: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.

#2 Luanub

    Lua Nub

  • Members
  • 1,135 posts
  • LocationPortland OR

Posted 21 April 2012 - 12: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


#3 OminousPenguin

  • Members
  • 93 posts

Posted 21 April 2012 - 05: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.

#4 PyromancerVx

  • Members
  • 8 posts

Posted 22 April 2012 - 05:08 AM

um what is the admin layer? I was testing in a normal world but near bedrock.

#5 OminousPenguin

  • Members
  • 93 posts

Posted 22 April 2012 - 11:44 AM

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.

#6 Luanub

    Lua Nub

  • Members
  • 1,135 posts
  • LocationPortland OR

Posted 22 April 2012 - 12: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?

#7 PyromancerVx

  • Members
  • 8 posts

Posted 22 April 2012 - 12:42 PM

I think I tested it on ground level too. Didn't work

#8 libraryaddict

  • New Members
  • 195 posts

Posted 22 April 2012 - 12: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






2 user(s) are reading this topic

0 members, 2 guests, 0 anonymous users