Jump to content




Help!

computer

2 replies to this topic

#1 elliotjarnit

  • Members
  • 7 posts

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


#2 supernicejohn

  • Members
  • 98 posts
  • LocationSweden

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! ;)

#3 Mao Zedong

  • Members
  • 14 posts
  • LocationFunctional Programming Zealot

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






1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users