Jump to content




Hey im making a area clearing program for turtles i need some help


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

#1 ravensniper72

  • Members
  • 13 posts

Posted 02 October 2014 - 09:56 PM

so ive been working on this program on and off throughout the day and i cant get it to work correctly i want it so that once its done clearing the outside to how ever high the area is for it to stop clearing and go back to the original spot can i get some help?

this is what i got

distance = read()

function funct1()

for i = 1, distance do
turtle.dig()
turtle.digUp()
turtle.forward()
turtle.digUp()
end
end

function funct2()

turtle.back()

end

function funct3()
turtle.up()
turtle.detectUp()
end

function funct4()
repeat
turtle.turnLeft()
funct1()
turtle.turnLeft()
funct1()
turtle.turnLeft()
funct1()
turtle.turnLeft()
funct1()
funct3()
until
turtle.detectDown() == flase

end

function funct5()
repeat
turtle.down()
until
turtle.detectDown() == true
end


--Main Program

funct1()
turtle.turnLeft()
funct1()
turtle.turnLeft()
funct1()
turtle.turnLeft()
funct1()
funct3()
if turtle.detectUp() == true then
funct4()
turtle.back()
turtle.turnLeft()
else if turtle.detectUp() == false then
funct5()
end
end

#2 Bomb Bloke

    Hobbyist Coder

  • Moderators
  • 7,099 posts
  • LocationTasmania (AU)

Posted 03 October 2014 - 01:23 AM

In funct4(), you've got "false" miss-spelt as "flase". Lua will assume "flase" is an undefined variable, and treat is as nil. turtle.detectDown() will never return nil and so the loop will never end.

This code digs around a rectangular border. Did you want it to clear out the inside of the area as well...?

#3 ravensniper72

  • Members
  • 13 posts

Posted 03 October 2014 - 01:43 AM

View PostBomb Bloke, on 03 October 2014 - 01:23 AM, said:

In funct4(), you've got "false" miss-spelt as "flase". Lua will assume "flase" is an undefined variable, and treat is as nil. turtle.detectDown() will never return nil and so the loop will never end.

This code digs around a rectangular border. Did you want it to clear out the inside of the area as well...?

K thanks i didn't see that error

#4 ravensniper72

  • Members
  • 13 posts

Posted 03 October 2014 - 10:15 PM

ok so i fixed what was miss spelled but now i ran into a few other problems it now doesnt continue after the first part
here is what it looks like now

distance = read()

function funct1()

for i = 1, distance do
turtle.dig()
turtle.digUp()
turtle.forward()
turtle.digUp()
end
end

function funct2()

turtle.back()

end

function funct3()
turtle.up()
turtle.detectUp()
end

function funct4()
repeat
turtle.turnLeft()
funct1()
turtle.turnLeft()
funct1()
turtle.turnLeft()
funct1()
turtle.turnLeft()
funct1()
funct3()
until
turtle.detectDown() == false

end

function funct5()
repeat
turtle.down()
until
turtle.detectDown() == true
end


--Main Program

turtle.dig()
turtle.forward()

funct1()
turtle.turnLeft()
funct1()
turtle.turnLeft()
funct1()
turtle.turnLeft()
funct1()
funct3()
if turtle.detectUp() == false then
funct4()
turtle.back()
turtle.turnLeft()
else if turtle.detectUp() == true then
funct5()
end
end

#5 KingofGamesYami

  • Members
  • 3,002 posts
  • LocationUnited States of America

Posted 04 October 2014 - 12:33 AM

Ugh, no [ code ][ /code ] tags or pastebin links. I greatly dislike un-indented code. A lot of basic mistakes are revealed by that.

#6 Dragon53535

  • Members
  • 973 posts
  • LocationIn the Matrix

Posted 04 October 2014 - 12:42 AM

distance = read()
function funct1()
  for i = 1, distance do
    turtle.dig()
    turtle.digUp()
    turtle.forward()
    turtle.digUp()
  end
end
function funct2()
  turtle.back()
end
function funct3()
  turtle.up()
  turtle.detectUp()
end
function funct4()
  repeat
    turtle.turnLeft()
    funct1()
    turtle.turnLeft()
    funct1()
    turtle.turnLeft()
    funct1()
    turtle.turnLeft()
    funct1()
    funct3()
  until turtle.detectDown() == false
end
function funct5()
  repeat
    turtle.down()
  until turtle.detectDown() == true
end

--Main Program
turtle.dig()
turtle.forward()
funct1()
turtle.turnLeft()
funct1()
turtle.turnLeft()
funct1()
turtle.turnLeft()
funct1()
funct3()
if turtle.detectUp() == false then
  funct4()
  turtle.back()
  turtle.turnLeft()
else if turtle.detectUp() == true then
  funct5()
end
end --#This serves no purpose. and will error.


#7 KingofGamesYami

  • Members
  • 3,002 posts
  • LocationUnited States of America

Posted 04 October 2014 - 01:48 AM

Change this
else if
to this
elseif
and remove one end.

#8 ravensniper72

  • Members
  • 13 posts

Posted 04 October 2014 - 09:56 PM

ok thanks and sorry i just havent gotten used to indenting yet.





2 user(s) are reading this topic

0 members, 2 guests, 0 anonymous users