6 posts
Location
Canada
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
7083 posts
Location
Tasmania (AU)
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…?
6 posts
Location
Canada
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
6 posts
Location
Canada
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
3057 posts
Location
United States of America
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.
1080 posts
Location
In the Matrix
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.
3057 posts
Location
United States of America
Posted 04 October 2014 - 02:48 AM
Change this
else if
to this
elseif
and remove one end.
6 posts
Location
Canada
Posted 04 October 2014 - 10:56 PM
ok thanks and sorry i just havent gotten used to indenting yet.