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

<eof> error at else

Started by Kron, 06 February 2013 - 12:17 AM
Kron #1
Posted 06 February 2013 - 01:17 AM
Hi guys, im on a phn so grammar wont be best. Anyways, im having issues with my code… it seems that I continue to get the error <EOF> expexted at else.

print("Insert Password")
io.write("» ")
if read("*") == "test" then
print("Password ACCEPTED")
sleep(2)
end
else
print("DOH")
end
end


Please help!
Skullblade #2
Posted 06 February 2013 - 01:18 AM
Delete the end right before the else…not needed
remiX #3
Posted 06 February 2013 - 02:44 AM
To extend on what Skullblade said…

A full if / function / loop block needs to end with only one end.

if ... then
..
elseif .. then

else

end

You can also use elseif's for more conditions.
TheOddByte #4
Posted 06 February 2013 - 07:42 AM
If you still having problems then here are the code:



print("Insert Password")
io.write("» ")
if read("*") == "test" then
print("Password ACCEPTED")
sleep(2)
else
print("DOH")
end


You could also do this to improve the code:
Spoiler


while true do -- So it's looping until it's correct

term.clear()  --This Clears The Screen
term.setCursorPos(1,1) -- This Sets The Position to X:1 Y:1

print("Insert Password")
io.write("» ")
if read("*") == "test" then
print("Password ACCEPTED")
sleep(2)
return  -- Here It Breaks From The Loop

else
print("DOH")
sleep(2)
	   end -- Ends The "while true do"
		 end --Ends The "if"

--[[
If It Had Been An Function You would have needed
another end ofcourse,
I hope any of this helped you! =)
]]--
Kron #5
Posted 06 February 2013 - 02:52 PM
None of the above worked. Also, I'm doing it on notepad++ and sigmascript. Could this be part of the issue?
Orwell #6
Posted 06 February 2013 - 02:55 PM
None of the above worked. Also, I'm doing it on notepad++ and sigmascript. Could this be part of the issue?
Define "not working". I don't see anything wrong with Hellkid98's snippet.
Zoinky #7
Posted 06 February 2013 - 04:34 PM
Tested Hellkid98's snippet on ccemu. Nothing wrong. Something has probably gone wrong while you were copying/pasting. You should look over the code you have.
ChunLing #8
Posted 06 February 2013 - 11:01 PM
To reiterate a point, when you have modified your code and it is still not performing as desired, you must post the current code and a precise description of the undesired behavior (including complete error message or other output), in order to obtain further help to be relevant to your situation.