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

Help!

Started by elliotjarnit, 19 November 2016 - 03:23 PM
elliotjarnit #1
Posted 19 November 2016 - 04:23 PM
So im trying to make a
1: Password file maker(Works)
2: Password protected computer that when you type in a password in a file(password) then it breaks and ends(Not Working)
Here's the code for the first one:

write("New Password: ")
input = read()
if input == "F" then
shell.run("startup")
end
local file = fs.open("password", "w")
file.writeLine(input)
file.close()
Now the one thats not working(Called startup):

write("Enter Password: ")
user = read()
local file = fs.open("password", "r")
file.readLine()
file.close()
if user == file then
print("Correct!")
sleep(2)
shell.run("system")
else
print("Incorrect")
sleep(2)
os.reboot()
end
supernicejohn #2
Posted 19 November 2016 - 05:50 PM
You would want to save the result of 'file.readLine' into a variable, then compare that instead of comparing a string with a file handle.
The wiki has good support on the fs API
Good luck! ;)/>
Mao Zedong #3
Posted 19 November 2016 - 06:16 PM

write("Enter Password: ")
user = read()
local file = fs.open("password", "r")
local pass = file.readLine()
file.close()
if user == pass then
print("Correct!")
sleep(2)
shell.run("system")
else
print("Incorrect")
sleep(2)
os.reboot()
end