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

multiple user login program returning eof

Started by cowman001, 20 August 2012 - 01:21 PM
cowman001 #1
Posted 20 August 2012 - 03:21 PM
So i built this multi user login and there is something wrong with my if statements because they keep returning errors and i cant seem to fix it.. it says the error is at line 30 (eof) which is where the first if statement is

 os.pullEvent = os.pullEventRaw term.clear() term.setCursorPos(1,1) user = "" pass = "" textutils.slowPrint ("Welcome to local pc: #0") textutils.slowPrint ("Please log in.") textutils.slowWrite ("Username: ") user = read() textutils.slowWrite ("Password: ") pass = read("*") textutils.slowWrite ("Logging in") sleep(1) write "." sleep(.8) write "." sleep(.6) write "." sleep(.4) write "." sleep(.2) write "." term.clear() term.setCursorPos(1,1) if user == "Caleb" or "caleb" or "Cowman" or "cowman" and pass == "socks321" then textutils.slowWrite("Welcome back Caleb!\n") shell.run("time") shell.setDir("/users/caleb") end else if user == "Surf" or "surf" or "surfcash" or "Surfcash" and pass == "password" then textutils.slowWrite("Welcome back Colin!\n") shell.run("time") shell.setDir("/users/colin") fs.isReadOnly("/") fs.isReadOnly("/rom") fs.isReadOnly("/users/caleb") end else if user == ("Guest" or "guest") and pass == ("guest" or "password") then textutils.slowWrite("Welcome Guest.User!\n") shell.run("time") shell.setDir("/users/guest") fs.isReadOnly("/") fs.isReadOnly("/rom") fs.isReadOnly("/users/caleb") fs.isReadOnly("/users/colin") end else textutils.slowWrite("Incorrect User or Password.") sleep(3) shell.run("startup") end
cowman001 #2
Posted 20 August 2012 - 03:22 PM
Im on my phone as my internet is out atm and im not sure if the code posted correctly here it is again…




os.pullEvent = os.pullEventRaw term.clear() term.setCursorPos(1,1) user = "" pass = "" textutils.slowPrint ("Welcome to local pc: #0") textutils.slowPrint ("Please log in.") textutils.slowWrite ("Username: ") user = read() textutils.slowWrite ("Password: ") pass = read("*") textutils.slowWrite ("Logging in") sleep(1) write "." sleep(.8) write "." sleep(.6) write "." sleep(.4) write "." sleep(.2) write "." term.clear() term.setCursorPos(1,1) if user == "Caleb" or "caleb" or "Cowman" or "cowman" and pass == "socks321" then textutils.slowWrite("Welcome back Caleb!\n") shell.run("time") shell.setDir("/users/caleb") end else if user == "Surf" or "surf" or "surfcash" or "Surfcash" and pass == "password" then textutils.slowWrite("Welcome back Colin!\n") shell.run("time") shell.setDir("/users/colin") fs.isReadOnly("/") fs.isReadOnly("/rom") fs.isReadOnly("/users/caleb") end else if user == ("Guest" or "guest") and pass == ("guest" or "password") then textutils.slowWrite("Welcome Guest.User!\n") shell.run("time") shell.setDir("/users/guest") fs.isReadOnly("/") fs.isReadOnly("/rom") fs.isReadOnly("/users/caleb") fs.isReadOnly("/users/colin") end else textutils.slowWrite("Incorrect User or Password.") sleep(3) shell.run("startup") end
Cranium #3
Posted 20 August 2012 - 03:31 PM

os.pullEvent = os.pullEventRaw
term.clear()
term.setCursorPos(1,1)
user = ""
pass = ""
textutils.slowPrint ("Welcome to local pc: #0")
textutils.slowPrint ("Please log in.")
textutils.slowWrite ("Username: ")
user = read()
textutils.slowWrite ("Password: ")
pass = read("*")
textutils.slowWrite ("Logging in")
sleep(1)
write "." sleep(.8)
write "."
sleep(.6)
write "."
sleep(.4)
write "."
sleep(.2)
write "."
term.clear()
term.setCursorPos(1,1)
if user == "Caleb" or "caleb" or "Cowman" or "cowman" and pass == "socks321" then
textutils.slowWrite("Welcome back Caleb!n")
shell.run("time")
shell.setDir("/users/caleb")
--remove "end" until actual end of if/elseif commands
elseif user == "Surf" or "surf" or "surfcash" or "Surfcash" and pass == "password" then --needs to be elseif
textutils.slowWrite("Welcome back Colin!n")
shell.run("time")
shell.setDir("/users/colin")
fs.isReadOnly("/")
fs.isReadOnly("/rom")
fs.isReadOnly("/users/caleb")
--remove "end" until actual end of if/elseif commands
elseif user == ("Guest" or "guest") and pass == ("guest" or "password") then
textutils.slowWrite("Welcome Guest.User!n")
shell.run("time")
shell.setDir("/users/guest")
fs.isReadOnly("/")
fs.isReadOnly("/rom")
fs.isReadOnly("/users/caleb")
fs.isReadOnly("/users/colin")
--remove "end" until actual end of if/elseif commands
else textutils.slowWrite("Incorrect User or Password.")
sleep(3)
shell.run("startup")
end --end goes here.
What you can do to simplify your code is when asking for the password, use

local user = tolower(read()) --will automatically make it as lowercase, thus only needing you to define if user == "caleb"
You should also use local variables as often as possible. That way, any variables you use in the future will not conflict with any programs.