Posted 10 August 2017 - 09:54 PM
Hey there,
I've got a computer in my house which controls access to the machine room (machines and ME system) via a teleporter.
We're a couple friends on the server, so for gits and shiggles I created a login system for the access terminal.
This works fine for the first user in the file; all the other users will not work this way.
The file is structured as follows:
I wrote this piece of code and it only just came to me that it wasn't working correctly:
The result I'm looking for and also expecting in the other functions, is a table looking something like this, which the above code does not produce.
Essentially, I'm trying to do this (jotted down C# code), if it makes it clearer…
Thanks in advance for any and all help; sorry if I didn't make myself clear enough!
I've got a computer in my house which controls access to the machine room (machines and ME system) via a teleporter.
We're a couple friends on the server, so for gits and shiggles I created a login system for the access terminal.
This works fine for the first user in the file; all the other users will not work this way.
The file is structured as follows:
user0 password
user1 password
...
I wrote this piece of code and it only just came to me that it wasn't working correctly:
-- [[ Functions ]] --
local function getUsers()
handle = fs.open(userConf, "r")
if handle == nil then
return userTable, 0
else
local rawData = handle.readAll()
print(rawData)
for s in string.gmatch(rawData, ".*$") do
-- do stuff with line
userSplit = {}
for word in s:gmatch("%w+") do
table.insert(userSplit, word)
--print(word)
--sleep(2)
end
table.insert(userTable, userSplit)
end
return userTable, #userTable
end
end
The result I'm looking for and also expecting in the other functions, is a table looking something like this, which the above code does not produce.
local users = {
{ "user0", "password" },
{ "user1", "password" },
...
}
Essentially, I'm trying to do this (jotted down C# code), if it makes it clearer…
Dictionary<string, string> GetUsers() {
var lines = File.readAllLines("/path/to/file.conf");
var returnVal = new Dictionary<string, string>();
foreach (var line in lines) {
var split = Regex.Split(line, @"\s{1,}");
returnVal.Add(split[0], split[1]);
}
return returnVal;
}
Thanks in advance for any and all help; sorry if I didn't make myself clear enough!