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

'end' expected. I do have 'end' written down.

Started by jaeeonr, 25 December 2012 - 08:59 PM
jaeeonr #1
Posted 25 December 2012 - 09:59 PM
Hello, I'm trying to get this program to work, but apparently it just gives me a nonsense error message. bios:338:
[string "test1"]:18: 'end' expected (to close 'if' at line 17) [CODE]
for 1=1,2 do
  turtle.digDown()
  turtle.down()
end

dir2go = 2
for i=1,3 do
  for i = 1,2 do
    turtle.dig()
    turtle.digDown()
    turtle.forward()
  end
  turtle.digDown()
  if i == "3" then	 <-------------------line 17
    break()
  end
  if dir2go == 1 then
    bla bla bla
  else
    bla bla bla
  end
end
WHAT IS WRONG WITH THIS CODE???
Sammich Lord #2
Posted 25 December 2012 - 10:23 PM
You forgot to put the ['/code'] at the bottom without the '. Here is a version with comments that SHOULD work:

-- Indenting is your friend
for i=1,2 do
  turtle.digDown()
  turtle.down()
end

local dir2go = 2
for h=1,3 do
  for i = 1,2 do -- You have conflicting i vars
    turtle.dig()
    turtle.digDown()
    turtle.forward()
  end
  turtle.digDown()       -- Didn't need the break thingy. Also, break isn't a function
  if dir2go == 1 then    -- it is a word. So you just put "break"
    print("bla bla bla") -- For loops also end after reaching the number stated
  else
    print("blah")
  end
end