Here is my code that pertains to saving/loading/registering users in a table:
--save/load
local function saveUsers(tUsers)
if type(tUsers)=='table' then
local oFile=io.open('users','w')
oFile:write(textutils.serialize(tUsers))
oFile:close()
return true
end
end
local function loadUsers()
local loading = true
if fs.exists('users') then
local oFile=io.open('users','r')
local tList=textutils.unserialize(oFile:read())
oFile:close()
return tList
else
print("ERROR! Users file not found")
end
end
--registration
local function register(id,username,password)
print("Registration request from Computer "..id)
local tUsers=loadUsers()
if tUsers[id] then --this is the error I receive
rednet.send(id,"Exists")
print("Account already registered")
else
tUsers[id]={}
tUsers[id].username = username
tUsers[id].password = password
tUsers[id].mail={}
saveUsers(tUsers)
print('Successfully registered Computer '..id..' as username "'..username..'"')
rednet.send(id,"Success")
end
end
I have no other way to detect if a user exists other than this. Any help would be apprecieated.