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

if statement help. "SOLVED"

Started by Emilgardis, 29 July 2012 - 10:22 AM
Emilgardis #1
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.
Bonum #2
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?
ChiknNuggets #3
Posted 29 July 2012 - 12:39 PM
well <eof> expected is because you have break end when its just break
Emilgardis #4
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.
ChiknNuggets #5
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.")
Emilgardis #6
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")
Tiin57 #7
Posted 29 July 2012 - 01:22 PM
Sorry, do you still have an issue?
Emilgardis #8
Posted 29 July 2012 - 01:54 PM
Nope.
I never had a issue. :ph34r:/>/>
Tiin57 #9
Posted 29 July 2012 - 02:13 PM
Oh, ok. Good.