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

Can anyone see any errors?

Started by ShadowLamp, 08 November 2014 - 03:04 AM
ShadowLamp #1
Posted 08 November 2014 - 04:04 AM
Spoiler

os.pullEvent = os.pullEventRaw
 term.clear()
 term.setCursorPos(13,1)
print("Welcome To The Vaults.")
  sleep(1)
term.setCursorPos(1,2)
print("--------------------------------------------------")
sleep(1)
term.setCursorPos(1,4)
 local input = read("*")
local saves = fs.open("userList","r")
local users = textutils.unserialize(saves.readAll())
saves.close()
print("Signin or Signup?")
local input = read()
if input == "Signin" then
  print("Enter Username: ")
local userInput = read()
  print("Enter Password: ")
local passInput = read("*")
if users[userInput] == passInput then
  print("Welcome back")
  redstone.setOutput("left",true)
  sleep(2)
  redstone.setOutput("left",false)
os.shutdown()
elseif input == "StaffPw" then
term.clear()
term.setCursorPos(11,1)
print("Welcome back, Staff Member")
term.setCursorPos(1,3)
print("--------------------------------------------------")
rs.setOutput("left",true)
sleep(2)
rs.setOutput("left",false)
os.shutdown()
  elseif input == "Debugging" then
term.clear()
term.setCursorPos(7,1)
write("Logging Out of the Secure Network")
sleep(0.5)
term.clear()
term.setCursorPos(7,1)
write("Logging Out of the Secure Network.")
sleep(0.5)
term.clear()
term.setCursorPos(7,1)
write("Logging Out of the Secure Network..")
sleep(0.5)
term.clear()
term.setCursorPos(7,1)
write("Logging Out of the Secure Network...")
sleep(1)
term.setCursorPos(1,2)
print("--------------------------------------------------")
sleep(0.5)
term.clear()
term.setCursorPos(7,1)
print("Unsecure Debugging System Operational")
term.setCursorPos(1,2)
print("--------------------------------------------------")
sleep(0.5)
error()
else
  term.clear()
term.setCursorPos(13,1)
print("This Isn't Your Vault!")
term.setCursorPos(1,2)
print("---------------------------------------------------")
sleep(1)
os.shutdown()
end
else
   print("Wrong Username or Password!")
end
elseif input == "Signup" then
  print("Enter New Username: ")
local userInput = read()
  print("Enter New Password: ")
local passInput = read("*")
users[userInput] = passInput
else
  print("Wrong Username or Password. Try again.")
sleep(1)
os.reboot()
local saves = fs.open("userList","w")
saves.writeLine(textutils.serialize(users))
saves.close()      

This will just not work. The error message says that an end is expected on line 75, the tells me that the end shouldn't be there with the "eof" thing.

Thank you for helping.

-Billy.
theoriginalbit #2
Posted 08 November 2014 - 04:13 AM
This is where indentation is important, take a look at your code with indentation applied

Indented Code

os.pullEvent = os.pullEventRaw
term.clear()
term.setCursorPos(13,1)
print("Welcome To The Vaults.")
sleep(1)
term.setCursorPos(1,2)
print("--------------------------------------------------")
sleep(1)
term.setCursorPos(1,4)
local input = read("*")
local saves = fs.open("userList","r")
local users = textutils.unserialize(saves.readAll())
saves.close()
print("Signin or Signup?")
local input = read()
if input == "Signin" then
  print("Enter Username: ")
  local userInput = read()
  print("Enter Password: ")
  local passInput = read("*")
  if users[userInput] == passInput then
	print("Welcome back")
	redstone.setOutput("left",true)
	sleep(2)
	redstone.setOutput("left",false)
	os.shutdown()
  elseif input == "StaffPw" then
	term.clear()
	term.setCursorPos(11,1)
	print("Welcome back, Staff Member")
	term.setCursorPos(1,3)
	print("--------------------------------------------------")
	rs.setOutput("left",true)
	sleep(2)
	rs.setOutput("left",false)
	os.shutdown()
  elseif input == "Debugging" then
	term.clear()
	term.setCursorPos(7,1)
	write("Logging Out of the Secure Network")
	sleep(0.5)
	term.clear()
	term.setCursorPos(7,1)
	write("Logging Out of the Secure Network.")
	sleep(0.5)
	term.clear()
	term.setCursorPos(7,1)
	write("Logging Out of the Secure Network..")
	sleep(0.5)
	term.clear()
	term.setCursorPos(7,1)
	write("Logging Out of the Secure Network...")
	sleep(1)
	term.setCursorPos(1,2)
	print("--------------------------------------------------")
	sleep(0.5)
	term.clear()
	term.setCursorPos(7,1)
	print("Unsecure Debugging System Operational")
	term.setCursorPos(1,2)
	print("--------------------------------------------------")
	sleep(0.5)
	error()
  else
	term.clear()
	term.setCursorPos(13,1)
	print("This Isn't Your Vault!")
	term.setCursorPos(1,2)
	print("---------------------------------------------------")
	sleep(1)
	os.shutdown()
  end
else
print("Wrong Username or Password!")
end
elseif input == "Signup" then
  print("Enter New Username: ")
  local userInput = read()
  print("Enter New Password: ")
  local passInput = read("*")
  users[userInput] = passInput
else
  print("Wrong Username or Password. Try again.")
  sleep(1)
  os.reboot()
  local saves = fs.open("userList","w")
  saves.writeLine(textutils.serialize(users))
  saves.close()  

you'll notice two things:
  1. you're missing an end after the last else statement;
  2. you have an invalid if statement, where your last else and elseif hove no if statement relates to them; and
I have a feeling that your else statement at line 73-75 was a mistake, remove it, add an end to the very end, and you should be all fixed.

EDIT: it should be noted, that in your final else branch that the computer restarts immediately when you invoke os.reboot, therefore your program would never write the userList file
Edited by
ShadowLamp #3
Posted 08 November 2014 - 04:17 AM
Thank you! You're a life saver! I've been working on this all night, I got so frustrated when it didn't work, after I'd tested it a few times.