15 posts
Posted 29 July 2012 - 12:22 PM
Hello!
This is me with heavy noob code.
x = 0
while turtle.detect() do
turtle.dig()
turtle.digUp()
turtle.up()
x = x + 1
end
if turtle.detectDown() then
print("Finished")
end
else
turtle.down()
end
print("The tree was "..x.." spaces")
I get the error, bios:204 '<eof>' expected.
I already know how to fix this. But if I want to break the if statement, how would I do that? I've tried to do
print("Finished") then
break end
end
But that did not work.
Also could you give me any improvements, but not full code please, I am still trying to learn lua, and I think the best way to learn is to have errors and trials.
9 posts
Posted 29 July 2012 - 12:33 PM
Ooops, I did not read the question before replying. What do you mean by breaking an if statement?
127 posts
Posted 29 July 2012 - 12:39 PM
well <eof> expected is because you have break end when its just break
15 posts
Posted 29 July 2012 - 12:45 PM
Thanks for the replies.
I'm just going to ignore this as it is inefficent.
::Edit:: Yes I was able to do it.
127 posts
Posted 29 July 2012 - 12:51 PM
here is just a little improvement it removes about 3 lines and also it doesnt go down until it hits the ground but it goes back down to the starting position( it doesnt have to be done this way obviously but its the way i like it) i havent actually tested this code but should work just fine
x = 0
while turtle.detect() do
turtle.dig()
turtle.digUp()
turtle.up()
x = x + 1
end
max = x
while x > 0 do
turtle.down()
x = x - 1
end
print("Finished, The tree was "..max.." blocks tall.")
15 posts
Posted 29 July 2012 - 01:16 PM
here is just a little improvement it removes about 3 lines and also it doesnt go down until it hits the ground but it goes back down to the starting position( it doesnt have to be done this way obviously but its the way i like it) i havent actually tested this code but should work just fine
x = 0
while turtle.detect() do
turtle.dig()
turtle.digUp()
turtle.up()
x = x + 1
end
max = x
while x > 0 do
turtle.down()
x = x - 1
end
print("Finished, The tree was "..max.." blocks tall.")
Thank you for that, even thou I made a better version before. ::Edit:: They are the same!!!!
x = 0
while turtle.detect() do
turtle.dig()
turtle.digUp()
turtle.up()
x = x + 1
end
down = x+0
while turtle.detectDown() == false and down ~= 0 do
turtle.down()
down = down-1
end
print("The tree was "..x.." spaces")
1243 posts
Location
Indiana, United States
Posted 29 July 2012 - 01:22 PM
Sorry, do you still have an issue?
15 posts
Posted 29 July 2012 - 01:54 PM
Nope.
I never had a issue. :ph34r:/>/>
1243 posts
Location
Indiana, United States
Posted 29 July 2012 - 02:13 PM
Oh, ok. Good.