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

[error] end expected to close function?

Started by craton, 14 June 2012 - 03:50 PM
craton #1
Posted 14 June 2012 - 05:50 PM
I just cant figure out what's wrong with it. Help would be gladly appreciated.

hear is the code.

function a()
turtle.back()
turtle.place()
turtle.turnRight()
turtle.turnRight()
if turtle.detect() then
turtle.up()
turtle.placeDown()
shel.exit()
end
else
turtle.turnRight()
turtle.turnRight()
end
end
function p()
turtle.select(1)
a()
end
if turtle.getItemCount(1) == 0 then
turtle.select(2)
a()
end
while true do
p()
end
MysticT #2
Posted 14 June 2012 - 05:55 PM
The problem is here:

if turtle.detect() then
  turtle.up()
  turtle.placeDown()
  shel.exit()
end -- extra end
else
  turtle.turnRight()
  turtle.turnRight()
end
The if syntax is:

if <condition> then
  -- code
else
  -- code
end
craton #3
Posted 14 June 2012 - 05:59 PM
wow i cant beleve i over looked that. Thanks! :(/>/>
BigSHinyToys #4
Posted 14 June 2012 - 06:02 PM
[EDIT]
beaten by 7 mins ow well

you use a "end" an the end of an if. you don't need it before the else part only at then end

FIXED
Spoiler

function a()
	turtle.back()
	turtle.place()
	turtle.turnRight()
	turtle.turnRight()
	sleep(2)
	if turtle.detect() then
		turtle.up()
		turtle.placeDown()
        shell.exit() -- spelling
	else
		turtle.turnRight()
		turtle.turnRight()
	end
end
function p()
	turtle.select(1)
	a()
end
if turtle.getItemCount(1) == 0 then
turtle.select(2)
a()
end
while true do
	p()
end