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

Read / Write to files in programs fs.open()

Started by Mitzey234, 21 June 2012 - 01:31 AM
Mitzey234 #1
Posted 21 June 2012 - 03:31 AM
So here is my code
Spoiler–Settings
a = "************************************************"
b = "* System Lock *"
c = "************************************************"
d = "************************************************"
e = "-"
f = "************************************************"
g = "-"
h = "************************************************"
i = " ****************************************"
j = " * *"
k = " ****************************************"
error = " Unable to start OS"
OS = "os"
function os.pullEvent()
local event, p1, p2, p3, p4, p5 = os.pullEventRaw()
if event == "terminate" then
term.setCursorPos(22,16)
print "NO HACK"
term.setCursorPos(18,4)
sleep(1.5)
shell.run("startup")
end
return event, p1, p2, p3, p4, p5
end
term.setCursorBlink( false )
–Settings
–Display
term.clear()
term.setCursorPos(1,1)
print (a)
print (:P/>/>
print ©
term.setCursorPos(1,5)
print (d)
print (e)
print (f)
print (g)
print (h)
term.setCursorPos(1,15)
print (i)
print (j)
print (k)
–Display
–Display Username
term.setCursorPos(2,8)
print "Password: "
term.setCursorPos(2,6)
write "Username: "
user = read()
–Display Username
–Username Correct
if fs.exists("Users/"..user) then
Call = io.open("Users/"..user, "r")
–Username Correct
–Display Password
term.setCursorPos(2,8)
write "Password: "
pass = read "*"
–Display Password
–Password Correct
if pass == Call:lines() then
term.setCursorPos(7,16)
print "…Loging In…"
sleep(2)
if fs.exists("os") then
shell.run("os")
else
term.clear()
term.setCursorPos(1,1)
print (a)
print (:)/>/>
print ©
term.setCursorPos(1,5)
print (d)
print (e)
print (f)
print (g)
print (h)
term.setCursorPos(1,15)
print (i)
print (j)
print (k)
term.setCursorPos(7,16)
print (error)
sleep(2)
term.setCursorPos(7,16)
print " Reboot in: 5 Seconds "
sleep(1)
term.clear()
term.setCursorPos(1,1)
print (a)
print (B)/>/>
print ©
term.setCursorPos(1,5)
print (d)
print (e)
print (f)
print (g)
print (h)
term.setCursorPos(1,15)
print (i)
print (j)
print (k)
term.setCursorPos(7,16)
print " Reboot in: 4 Seconds "
sleep(1)
term.clear()
term.setCursorPos(1,1)
print (a)
print (B)/>/>
print ©
term.setCursorPos(1,5)
print (d)
print (e)
print (f)
print (g)
print (h)
term.setCursorPos(1,15)
print (i)
print (j)
print (k)
term.setCursorPos(7,16)
print " Reboot in: 3 Seconds "
sleep(1)
term.clear()
term.setCursorPos(1,1)
print (a)
print (B)/>/>
print ©
term.setCursorPos(1,5)
print (d)
print (e)
print (f)
print (g)
print (h)
term.setCursorPos(1,15)
print (i)
print (j)
print (k)
term.setCursorPos(7,16)
print " Reboot in: 2 Seconds "
sleep(1)
term.clear()
term.setCursorPos(1,1)
print (a)
print (B)/>/>
print ©
term.setCursorPos(1,5)
print (d)
print (e)
print (f)
print (g)
print (h)
term.setCursorPos(1,15)
print (i)
print (j)
print (k)
term.setCursorPos(7,16)
print " Reboot in: 1 Second "
sleep(1)
os.reboot()
end
–Password Correct
else
–Password Incorrect
term.setCursorPos(7,16)
print " Incorrect Password"
sleep(2)
os.reboot()
end
–Password Incorrect
else
–Username Incorrect
term.setCursorPos(7,16)
print " Username does not exist"
sleep(2)
os.reboot()
–Username Incorect
end
And it is a login screen. but here is what it does. When i starts it needs a file called "Users" and then a user account name.
EX:
Username: test
then the file is test.txt and inside is the password.
It works with finding the username…
But not the password inside the file…
I tried lot's with this.
Help me out…
ardera #2
Posted 21 June 2012 - 05:03 AM
you can use the fs api, I think its better. Replace this piece of code in your program:

Call = io.open("Users/"..user, "r")
--Username Correct
--Display Password
term.setCursorPos(2,8)
write "Password: "
pass = read "*"
--Display Password
--Password Correct
if pass == Call:lines() then
term.setCursorPos(7,16)
print "...Loging In..."
through this:

Call = fs.open("Users/"..user, "r")
--Username Correct
--Display Password
term.setCursorPos(2,8)
write "Password: "
pass = read "*"
--Display Password
--Password Correct
if pass == Call.readLine() then
term.setCursorPos(7,16)
print "...Loging In..."
cant_delete_account #3
Posted 21 June 2012 - 05:52 AM
Just change:

if pass == Call:lines()

To:

if pass == Call:readAll()