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

<eof> expected

Started by TigerMeister, 23 March 2017 - 02:43 PM
TigerMeister #1
Posted 23 March 2017 - 03:43 PM
Hello. I am trying to code an door lock for Tekkit classic and I cant just figure it out.


Its an username + password lock and I am trying to fix an master password.

Spoiler

local tUsers = { Zippcast = "Admin", Bodomo = "BroCo", Celyph = "password"}
master = TigerMeister
password = Tigernr2
function clear()
term.clear()
term.setCursorPos(1,1)
write("TigerMeister Security INC v2 ")
term.setCursorPos(1,2)
end
clear()
write("Username: ")
user = read()
clear()
write("Password: ")
pass = read("*")
if master == password then
sleep(1)
write("Terminal now unlocked, please save when done.")
else
if tUsers[user] == pass then
sleep(1)
write("Welcome "..user.."!")
rs.setOutput("left",true)
sleep(3)
rs.setOutput("left",false)
os.shutdown
end
else
write("Wrong Username or Password!")
sleep(5)
os.shutdown()
end

Any ideas on what I should do? And can I improve something?
FuzzyLitchi #2
Posted 23 March 2017 - 08:07 PM
If you want TigerMeister and Tigernr2 to be passwords and usernames you have to use them as string. Use this

master = "TigerMeister"
password = "Tigernr2"

Also instead of
if master == password then
you should compare user to master and pass to password as so
if user == master and pass == password then

Using more descriptive variable names such as master_username, master_password, read_user, read_password can ensure that these types of errors don't happen :)/>

If you have any other errors, please write down the error line number and message, or explain what happens :)/>
Edited on 23 March 2017 - 07:10 PM
valithor #3
Posted 23 March 2017 - 10:14 PM
Your if elseif structure is misformed, which is what is causing the oef error. Right now with all the code between the if statements removed this is what the structure looks like.


if master == password then

else
  if tUsers[user] == pass then
  end
else

end

Notice that I indented the code to make it to where the beginning of a block lines up with the close of the block. In this code there are multiple else statements which correspond to that first if, which is not allowed in almost all languages. You probably meant to do something like this:


if master == password then

elseif tUsers[user] == pass then

else

end

Notice that I changed the first else to a elseif, which makes it to where there is only a single else to the if statement.
TigerMeister #4
Posted 24 March 2017 - 05:04 PM
Thanks for help guys.
FuzzyLitchi #5
Posted 24 March 2017 - 09:12 PM
You're welcome :D/>