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

Weird program error

Started by jag, 26 September 2012 - 06:39 AM
jag #1
Posted 26 September 2012 - 08:39 AM
So I was playing on a server, and I made a computer and tried to make a login program.
This is the code:
Spoiler
function checkLogin(uname, pass)
  -- Yes, very easy to hack...
  if uname ~= "admin" and pass ~= "password" then
	return true
  else
	return false
  end
end

function login()
  local inputUname = ""
  local inputPass = ""

  while not checkLogin(inputUname, inputPass) do
	term.clear()
	if inputUname == "" or inputPass == "" then
	  term.setCursorPos(3,2)
	  print("Wrong username or password!")
	end
	term.setCursorPos(3,3)
	print("Username: ") -- 10 char long
	term.setCursorPos(3,4)
	print("Password: ") -- 10 char long

	-- Now comes the input
	term.setCursorPos(13,3)
	inputUname = read()
	term.setCursorPos(13,4)
	inputPass = read("*")
  end
  term.clear()
  term.setCursorPos(3,2)
  print("Correct login!")
  sleep(2)
end

login()
Also available on Pastebin.
But I'm keep on getting the error:
bios:206: [string "index"]:34: 'end' expected (to close 'function' at line 9)
(Now is a good time as any to say that the programs name is index)


Image:
Spoiler
(BTW I'm planning to make a OS, so that's why the folder is named OS)

EDIT: I tried the code on single player and it worked. So the server must have gotten the problem.
Spoiler

Doyle3694 #2
Posted 26 September 2012 - 08:59 AM
what if you put another 'end' at the end of your program? also, is there any more code in your program or is this all?

I saw everything having a proper end, but try it
jag #3
Posted 26 September 2012 - 09:37 AM
what if you put another 'end' at the end of your program? also, is there any more code in your program or is this all?

I saw everything having a proper end, but try it
I've tried, but still the same error…
And no, no other code in the program, it's just a start.
Doyle3694 #4
Posted 26 September 2012 - 10:03 AM
Why is your output before your input? that must be messing stuff up like crazy?
Luanub #5
Posted 26 September 2012 - 12:14 PM
The code is fine, it works the way it is.

Do any other programs error?

Try restarting the CC Computer, if that don't work try your computer, if that don't work the server may need to be restarted.

Although I agree with Doyle. You should prompt the user for the login/password before checking for it. The first thing you get on your screen is a message saying you input the wrong user/password.
jag #6
Posted 26 September 2012 - 12:38 PM
The code is fine, it works the way it is.

Do any other programs error?

Try restarting the CC Computer, if that don't work try your computer, if that don't work the server may need to be restarted.

Although I agree with Doyle. You should prompt the user for the login/password before checking for it. The first thing you get on your screen is a message saying you input the wrong user/password.
Yeah well the code should be
if inputUname ~= "" or inputPass ~= "" then
instead of
if inputUname == "" or inputPass == "" then