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

'end' expected (to close 'function' at line 10)

Started by RastagGaming, 23 April 2013 - 12:13 PM
RastagGaming #1
Posted 23 April 2013 - 02:13 PM
I've made this code:http://pastebin.com/4w2zjgit, but I can't seem to get it to work. The error message that keeps appearing is: 'end' expected (to close 'function' at line 10)
Lyqyd #2
Posted 24 April 2013 - 04:39 AM
Split into new topic.
Imque #3
Posted 24 April 2013 - 04:43 AM
You didnt close the function, you closed the if statement. Add another end
Alerith #4
Posted 24 April 2013 - 05:37 AM
function subir()  -- moves up 10 times
 if redstuone.getInput("right", true) then
 sleep(5)
 length=10
 for i=1,length,1 do
 turtle.up()
end
end
end
codecompass #5
Posted 24 April 2013 - 06:50 AM
Listen to what the computer is telling you - it tells you how to correct your code.

Firstly, nearly all loops need an end and do ifs and functions
so there are 2 errors I can see. Here's the fixed code


function descer() -- moves down 10 times
if redstone.getInput("left",true) then
sleep(5) --gives enough time for you to get on
length=10
for i=1,length,1 do
turtle.down()
end --closes loop
end -- closes if
end --closes function you missed this

function subir()  -- moves up 10 times
	 if redstuone.getInput("right", true) then
	 sleep(5)
	 length=10
		  for i=1,length,1 do
		  turtle.up()
		  end - closes loop
	   end - closes if
end - closes function you missed this too

while true do --infinite loop to check
descer()
subir()
end

Highly recommend Spacing (Like i did for function(subir)) shows where the ends should go