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

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

Started by ravensniper72, 02 October 2014 - 08:56 PM
ravensniper72 #1
Posted 02 October 2014 - 10: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
Bomb Bloke #2
Posted 03 October 2014 - 02: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…?
ravensniper72 #3
Posted 03 October 2014 - 02:43 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…?

K thanks i didn't see that error
ravensniper72 #4
Posted 03 October 2014 - 11: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
KingofGamesYami #5
Posted 04 October 2014 - 01:33 AM
Ugh, no
tags or pastebin links. I greatly dislike un-indented code. A lot of basic mistakes are revealed by that.
Dragon53535 #6
Posted 04 October 2014 - 01: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.
KingofGamesYami #7
Posted 04 October 2014 - 02:48 AM
Change this

else if
to this

elseif
and remove one end.
ravensniper72 #8
Posted 04 October 2014 - 10:56 PM
ok thanks and sorry i just havent gotten used to indenting yet.