Posted 14 June 2012 - 02:03 AM
I have been working on a simple door entry system, that allows a user to run an initial configuration of the code they want to use and the side of the console that it wants the output to be, however, I must of made a mistake in the code, but I cannot see what it is, if anyone could poke at the code and point me to the line number where I am going wrong I would be very grateful.
local pwfile ="pwfile.txt"
local sidefile ="sidefile.txt"
local file = fs.open (pwfile, "r")
local file2 = fs.open (sidefile, "r")
-- Checks if the password file and side file cfg exists
if file and file2 then
local password = file.readAll()
local side = file2.readAll()
file.close()
file2.close()
term.clear()
print("Key Code:")
print("Hit F9 to change your keycode")
local event, param1 = os.pullEvent(key)
-- Checks if f9 has been hit and opens change keycode dialogue
if param1 == 67 then
local pw = "pwfile.txt"
local file = fs.open (pwfile, "r")
file.close()
print("Please enter your current keycode:")
local input read("*")
-- checks the entered password is correct
if input == password then
print("Now enter your new keycode:")
local pwin read("*")
-- writes new password to file
local npwin = pwin
file = fs.open(pwfile, "w")
file.write(npwin)
file.close()
os.reboot()
else
print("Your keycode was incorrect")
sleep(5)
os.reboot()
end
-- runs actual password check to open door
local input = read("*")
if input == password then
print("Keycode correct!")
rs.setOutput(side, true)
sleep(5)
rs.setOutput(side, false)
os.reboot()
else
-- if keycode was not correct
print("Keycode incorrect")
sleep(2)
os.shutdown()
end
else
-- runs intial configuration of the system
print("Initial Configuration - Please enter your desired keycode:")
local inputpw = read("*")
local pwnew = inputpw
file = fs.open(pwfile, "w")
file.write(pwnew)
file.close()
term.clear()
print("Initial Configuration - Please enter the side of the console that the door is connected to\n Right | Left | Back")
local inputside = read()
local sidenew = inputside
file2 = fs.open(sidefile, "w")
file2.write(sidenew)
file2.close()
print("Settings configured OS will now reboot")
sleep(5)
os.reboot()
end
end