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

Help with end after if then else statment

Started by Rieu, 21 May 2015 - 04:37 AM
Rieu #1
Posted 21 May 2015 - 06:37 AM
I am currently working on a program that I am trying to expand its functionality and make it more user friendly. It was working fine, until I added an if statement that has an elseif statement at the end. Now if my understaning is correct, i would need an end end to close both if statements. If I place
end
end
at the end of the whole thing, I get the following error. bios:367: [string "a"]:63: '<eof>' expected
Thinking that I had one to many ends, I removed the last one so there was only one end. I got the following error when I did that. bios:367: [string "a"]:203: 'end' expected (to close 'for' at line 65)
I am thinking, that the if then else is using the end after the for loop and then the for loop is without an end. Any help you guys could give me would be appreciated a lot. This is driving me crazy.

Spoiler–Author: Ferrwolf
– This program is designed for user to place lava in two 2x18 areas

–Warns user to make sure lava is in place

if turtle.getItemCount(1) < 64 then
term.clear()
term.setCursorPos(1,5)
print("Please place 77 lava cells in the turtles inventory using slots 1 and 2")sleep(2)
sleep(2)
term.clear()
sleep(1)
term.setCursorPos(1,5)
print("Please place 77 lava cells in the turtles inventory using slots 1 and 2")sleep(2)
sleep(2)
term.clear()
sleep(1)
term.setCursorPos(1,5)
print("Please place 77 lava cells in the turtles inventory using slots 1 and 2")sleep(2)
sleep(2)
term.clear()
print("Once you place the items in the correct slot, please start me again.")
print("Shutting down in 3")
sleep(1)
print("2")
sleep(1)
print("1")
sleep(1)
os.shutdown()
elseif turtle.getItemcount(2) < 13 then
term.clear()
term.setCursorPos(1,5)
print("Please place 77 lava cells in the turtles inventory using slots 1 and 2")sleep(2)
sleep(2)
term.clear()
sleep(1)
term.setCursorPos(1,5)
print("Please place 77 lava cells in the turtles inventory using slots 1 and 2")sleep(2)
sleep(2)
term.clear()
sleep(1)
term.setCursorPos(1,5)
print("Please place 77 lava cells in the turtles inventory using slots 1 and 2")sleep(2)
sleep(2)
term.clear()
print("Once you place the items in the correct slot, please start me again.")
print("Shutting down in 3")
sleep(1)
print("2")
sleep(1)
print("1")
sleep(1)
os.shutdown()
end
– Turtle mines the first row of obsidian
for i=0,18 do
while not turtle.forward() do
turtle.attack()
turtle.dig()
end
– Sets the turtle up to mine the second row
turtle.turnRight()
turtle.dig()
while not turtle.forward() do
turtle.attack()
turtle.dig()
end
turtle.turnRight()
– Turtle mines the second row
for i=0,17 do
while not turtle.forward() do
turtle.attack()
turtle.dig()
end
end
– Turtle moves the the second plot and prepares to mine the 3rd row
turtle.turnLeft()
turtle.dig()
while not turtle.forward() do
turtle.attack()
turtle.dig()
end
turtle.dig()
while not turtle.forward() do
turtle.attack()
turtle.dig()
end
turtle.turnLeft()
– Turtle mines the 3rd row
for i=0,17 do
while not turtle.forward() do
turtle.attack()
turtle.dig()
end
end
– Turtle prepares to mine 4th row
turtle.turnRight()
turtle.dig()
while not turtle.forward() do
turtle.attack()
turtle.dig()
end
turtle.turnRight()
– Turtle mines the 4th row
for i=0,17 do
while not turtle.forward() do
turtle.attack()
turtle.dig()
end
end
– Returns turtle to starting point while placing lava
turtle.select(1)
for i=0,17 do
turtle.back()
turtle.place()
end
turtle.turnLeft()
turtle.back()
turtle.place()
turtle.turnLeft()
turtle.back()
turtle.place()
for i=0,16 do
turtle.back()
turtle.place()
end
turtle.turnRight()
turtle.back()
turtle.place()
turtle.back()
turtle.place()
turtle.turnRight()
for i=0,17 do
turtle.back()
turtle.place()
end
turtle.turnLeft()
turtle.back()
turtle.place()
turtle.turnLeft()
turtle.back()
turtle.place()
for i=0,4 do
turtle.back()
turtle.place()
end
turtle.select(2)
for i=0,12 do
turtle.back()
turtle.place()
end
–Placing water to make obsidian
turtle.up()
turtle.forward()
turtle.turnRight()
turtle.forward()
turtle.forward()
turtle.turnLeft()
turtle.forward()
turtle.forward()
turtle.forward()
turtle.forward()
turtle.place()
sleep(5)
turtle.place()

term.clear()
print("Complete!")

If it would help to have line numbers you can find the code at http://pastebin.com/ucfJpVx9
Edited on 21 May 2015 - 04:43 AM
Cranium #2
Posted 21 May 2015 - 07:03 AM
Missing an end at line 62 to close the for loop.
Rieu #3
Posted 21 May 2015 - 09:38 PM
Missing an end at line 62 to close the for loop.

Thank you for the reply. I can't believe I forgot to end the for loop. :blink:/>