{
user1 = {pass = "pass", key = " ",},
}
I then have code that gets the table and compares it to the pass part of it:
if users[user1][pass] == "pass" then
-- do stuff
end
but it seems that does not work, any ideas? thanks
{
user1 = {pass = "pass", key = " ",},
}
I then have code that gets the table and compares it to the pass part of it:
if users[user1][pass] == "pass" then
-- do stuff
end
users["user1"]["pass"]
users.user1.pass
In your second code block, user1 and pass are variables - if they aren't set to anything, then you can't index into the users table with them.
Did you mean?:users["user1"]["pass"]
Or perhaps?:users.user1.pass
{
pData = {
[1] = "something",
},
}
So you are saying your table looks like this?{ pData = { [1] = "something", }, }
Because that is what you are accessing on that line.
{
cody = {
"pass",
},
}
local a = "cody"
local b = "pass
{
a,
b,
}
{
cody = {
"pass",
},
}
local file = fs.open("/database/users", "r")
local dat = file.readAll()
users = textutils.unserialize(dat)
file.close()
{
cody = "pass",
}
{
"cody",
"pass",
}
if incoming[1] and incoming[2] == users[incoming[1]] then
Let's say your file content is this:{ cody = { "pass", }, }
And you've read that into "users" with this:local file = fs.open("/database/users", "r") local dat = file.readAll() users = textutils.unserialize(dat) file.close()
"users" now has a key called "cody", which is another table with a numeric index at 1, which is set to "pass".
It would be a bit simpler to build the table like this:{ cody = "pass", }
In which case "users" would end up with a "cody" key which was set to "pass".
Let's say you then receive a table over rednet, and stored that against, say, "incoming". If that table was built like so:{ "cody", "pass", }
… then "incoming" would have two numeric indexes, the first being set to "cody", the second being set to "pass".
Now to check if that username and password combo existed in users, we'd merely need to do:if incoming[1] and incoming[2] == users[incoming[1]] then
"if the first entry in the incoming table is non-nil, and the second entry is equal to the value of the key in users with the name equal to incoming's first entry, then…"