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

[LUA] [ERROR] Function wants extra 'ends'?

Started by sithrazer, 06 March 2013 - 12:28 AM
sithrazer #1
Posted 06 March 2013 - 01:28 AM
Title: [LUA] [ERROR] Function wants extra 'ends'?

I've got a function (1 'end') a while loop (2 'end's) and an if/then series (3 'end's), but I keep getting this error:
… 'end' expected (to close function at line 11)

pastebin'd code here: http://pastebin.com/TVareb3X

adding the extra 'end' makes the error stop, but for the life of me I just don't get the logic behind it. Is it a Lua thing or have I missed something?

EDIT:
I missed whitespace. 'else if' apparently isn't the correct syntax in Lua.
Edited on 06 March 2013 - 12:34 AM
Cranium #2
Posted 06 March 2013 - 02:10 AM
Split to new topic.

Your 'else if' statement should be 'elseif'
It should be one word.
sithrazer #3
Posted 06 March 2013 - 03:05 AM
Split to new topic.

Your 'else if' statement should be 'elseif'
It should be one word.

I threw out and restarted this thing several times last night, and six minutes after adding the post I finally got it. Go figure.
I should have specifically stated in the edit that I did find out 'elseif' was the right syntax, I was kinda vague there. Sorry.
Spongy141 #4
Posted 06 March 2013 - 03:46 AM
I know I'm not a "Pro" but you forgot to end this

else if slot == 16 then
       error("Out of materials")
     else
Cranium #5
Posted 06 March 2013 - 04:12 AM
I know I'm not a "Pro" but you forgot to end this

else if slot == 16 then
	   error("Out of materials")
	 else
that's the elseif we were talking about…
Spongy141 #6
Posted 06 March 2013 - 12:13 PM
I know I'm not a "Pro" but you forgot to end this

else if slot == 16 then
	   error("Out of materials")
	 else
that's the elseif we were talking about…
Oh lol, I didn't care to read what you guys were talking about, oh and Congratz on mod Cranium (We used to be on a server together, and did a couple of building projects)
Lyqyd #7
Posted 06 March 2013 - 12:40 PM
Don't post "answers" without reading the rest of the replies.
Revolution #8
Posted 06 March 2013 - 12:40 PM
Hi guys i have a similar problem with my program Its made to control the doors in my house depending on user input
Its meant to run a door program when you type in the correct phrase but at the moment nothing happens it just refreshes :(/>

while true do
term.clear()
term.setCursorPos(1,1)
write("Enter Door/Room: ")
input = read()
if input == "front door open" then
	 shell.run("fndon")

if input == "front door close" then
	 shell.run("fndoff")

if input == "games room open" then
	 shell.run("grmon")

if input == "games room close" then
	 shell.run("grmoff")

if input == "brads room open" then
	 shell.run("brmon")

if input == "brads room close" then
	 shell.run("brmoff")

if input == "madis room open" then
	 shell.run("scron")

if input == "madis room close" then
	 shell.run("scroof")

if input == "richs room open" then
	 shell.run("rrmon")

if input == "richs room close" then
	 shell.run("rrmoff")

else
   write("error")
end
end
end
end
end
end
end
end
end
end
end
Lyqyd #9
Posted 06 March 2013 - 12:42 PM
Every if but the first if should be `elseif` instead. Remove all but two of the `end`s.
Revolution #10
Posted 06 March 2013 - 12:48 PM
Thanks its working now i totally forgot about "elseif"

Thanks a billion!!