Posted 29 July 2013 - 09:32 AM
Ok, I'm getting into the world of tables/for loops/fs and I'm having problems (not a lot actually). The first problem that I have to face is that I can't run a single function. This is the entire code:
And this is my file (tablesData/file):
At this point, when I run this, I get this error when registering: startup:8: attempt to call nil
And when login: startup:12: attempt to call nil
I don't understand why or what couses it and I can't figure out for myself how to solve it, I searched in the wiki, the forums and nothing that could fix it. I also tried making the function login and register another program and using shell.run() but then when I enter R or L nothing happens….
Thanks for reading.
print("do you want to login or register? R/L")
input0 = read()
if input0 == "R" then
register()
--shell.run(register)
elseif input0 == "L" then
--shell.run(login)
login()
else
print("Incorrect answer! :(/>/>/> Try again!")
sleep(2)
sell.run(startup)
end
----[[
function login()
r = fs.open("tablesData/file","r")
usersNot = r.readLine()
passwordsNot = r.readLine()
users = textutils.unserialize(usersNot)
passwords = textutils.unserialize(passwordsNot)
r.close()
write("enter the username: ")
input1 = read()
write("enter the password: ")
input2= read()
loged = false
for i = 1, #passwords do
if users[i] == input and passwords[i] == input2 then
loged = true
end
end
print(loged)
if loged == true then
print("Welcome")
else
print("Get out of hier")
sleep(2)
os.reboot()
end
end
function register()
write("Please enter your username: ")
input3 = read()
write("Please enter your password: ")
input4 = read("*")
write("Please repeat your password: ")
input5 = read("*")
t = fs.open("tablesData/files","r")
usersGet = t.readLine()
passwordsGet = t.readLine()
t.close()
usersGot = textutils.unserialize(usersGet)
passwordsgot = textutils.unserialize(passwordsGet)
w = fs.open("tablesData/files","w")
if input4 == input5 then
table.insert(usersGot,#usersGot+1,input3)
table.insert(passwordsGot,#passwordsGot+1,input5)
usersC = textutils.serialize(usersGot)
passwordsC = textutils.serialize(passwordsGot)
w.writeLine(usersC)
w.writeLine(passwordsC)
else
print("The passwords don't mismatch, try again.")
register()
end
end
--]]--
And this is my file (tablesData/file):
{[1]="admin",[2]="user1",[3]="user2",}
{[1]="admin",[2]="pass1",[3]="pass2",}
At this point, when I run this, I get this error when registering: startup:8: attempt to call nil
And when login: startup:12: attempt to call nil
I don't understand why or what couses it and I can't figure out for myself how to solve it, I searched in the wiki, the forums and nothing that could fix it. I also tried making the function login and register another program and using shell.run() but then when I enter R or L nothing happens….
Thanks for reading.