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

'End' expected (to close ' function')

Started by Kyahne, 28 June 2013 - 11:19 PM
Kyahne #1
Posted 29 June 2013 - 01:19 AM
Title - (Noob-CC-Coder) 'End' expected (to close ' function')

ok i am a noob at computercraft its the only thing in FTB that i couldn't use at all (excluding mining turtle excavate, and tunnel)
so i decided to learn. I have watched a bit of direwolf20 (2-3 seasons) and started using the wiki. But enough non-sense.

I tried to make myself a auto harvest/replant program that does not use bonemeal (all the ones i found do) and i got this error

Bios : 337 : [string "FarmBot"] :107 : 'end' expected (to close 'function' at line 5)

can some1 tell me how to fix or help me finish my code?

pastebin code here "vb4rkuQD"

P.S. How do you use spoilers?
Lyqyd #2
Posted 29 June 2013 - 02:26 PM
Split into new topic.
Engineer #3
Posted 29 June 2013 - 03:30 PM
Spoiler

function Seed()
        turtle.select(1)
end

function EmptyInv()
  turtle.turnRight()
  turtle.turnRight()
  for i = 3, 16 do
  turtle.select(i)
  turtle.drop()
  turtle.turnRight()
  turtle.turnRight()
end

function Harvest()
  turtle.forward()
  turtle.digDown()
  Seed()
  turtle.placeDown()
end

function rowA()
        Harvest()
        Harvest()
        Harvest()
        Harvest()
        Harvest()
        Harvest()
        Harvest()
        Harvest()
        Harvest()
        turtle.forward()
        turtle.turnRight()
        turtle.forward()
        turtle.turnRight()
end

function rowB()
        Harvest()
        Harvest()
        Harvest()
        Harvest()
        Harvest()
        Harvest()
        Harvest()
        Harvest()
        Harvest()
        turtle.forward()
        turtle.turnLeft()
        turtle.forward()
        turtle.turnLeft()
end

function rowC()
        Harvest()
        Harvest()
        Harvest()
        Harvest()
        turtle.forward()
        Harvest()
        Harvest()
        Harvest()
        Harvest()
        turtle.forward()
        turtle.turnRight()
        turtle.forward()
        turtle.turnRight()
end

function Home()
        turtle.forward()
        turtle.forward()
        turtle.forward()
        turtle.forward()
        turtle.forward()
        turtle.forward()
        turtle.forward()
        turtle.forward()
        turtle.forward()
        turtle.forward()
        turtle.turnRight()
        turtle.forward()
        turtle.forward()
        turtle.forward()
        turtle.forward()
        turtle.forward()
        turtle.forward()
        turtle.forward()
        turtle.forward()
        turtle.forward()
        turtle.turnRight()
end

while true do
        rowA()
        rowB()
        rowA()
        rowB()
        rowC()
        rowB()
        rowA()
        rowB()
        rowA()
        Home()
        EmptyInv()
        sleep(3600)
end
Spoiler made with
Spoiler
tags! :)/>/>

I compressed the code with for-loops and correct indentation:
Spoiler

function Seed()
	turtle.select(1)
end

function EmptyInv()
	turtle.turnRight()
	turtle.turnRight()
	for i = 3, 16 do
		turtle.select(i)
		turtle.drop()
		turtle.turnRight()
		turtle.turnRight()
	end -- # You missed an end right here
end

function Harvest()
  turtle.forward()
  turtle.digDown()
  Seed()
  turtle.placeDown()
end

function rowA()
	for i = 1, 8 do
		Harvest()
	end
	turtle.forward()
	turtle.turnRight()
	turtle.forward()
	turtle.turnRight()
end

function rowB()
	for i = 1, 9 do
		Harvest()
	end
	turtle.forward()
	turtle.turnLeft()
	turtle.forward()
	turtle.turnLeft()
end

function rowC()
	for i = 1, 4 do
		Harvest()
	end
	turtle.forward()
	for i = 1, 4 do
		Harvest()
	end
	turtle.forward()
	turtle.turnRight()
	turtle.forward()
	turtle.turnRight()
end

function Home()
	for i = 1, 10 do 
		turtle.forward()
	end
	
	turtle.turnRight()
	for i = 1, 9 do
		turtle.forward()
	end
	turtle.turnRight()
end

while true do
        rowA()
        rowB()
        rowA()
        rowB()
        rowC()
        rowB()
        rowA()
        rowB()
        rowA()
        Home()
        EmptyInv()
        sleep(3600)
end

So, you have to close a for-loop to with end. Otherwise Lua doesnt know what commands it should execute in the for-loop.
Kyahne #4
Posted 30 June 2013 - 03:05 AM
Thanx Engineer Close Topic Please!!!!
albrat #5
Posted 01 July 2013 - 04:38 AM
:)/> it sometimes needs an extra set of eyes. Like Engineer I also spotted the missing end statement after a few seconds…

Lua is pretty good at showing you where to look for an error.

Bios : 337 : [string "FarmBot"] :107 : 'end' expected (to close 'function' at line 5)

This tells us that at line 107 the end statement is trying to close the function at line 5. This means there is a missing end statement somewhere between line 107 and 5.

so if you scan your code from line 5 downwards, noting each opening statement and checking for the close of that statement… you will find the error by process of elimination. (indentation helps with this kind of error finding - start a statement on the same indentation as you finish it on)