Table Lua checks names
Table Lua checks names
Now, I have a list that stores the names of "moderators."
moderator = ["user1"] = true, ["user2"] = true, ["user3"] = true
moderator = ["user1"] = true, ["user2"] = true, ["user3"] = true
I want that if the user is moderator (if his name is in the list), he will be able to add other names in the list (that is, make other users moderators)
1 Answer
1
moderators = ["user1"] = true, ["user2"] = true, ["user3"] = true
Create a function to check if someone is a moderator:
function isModerator(name)
if moderators[name] == true then
return true
end
return false
end
Then use it! If someone is a moderator, then allow them to add a new key-value pair to the moderators
table:
moderators
if isModerator("user2") then
moderators["otherName"] = true
end
@lhf, ah, of course. Thanks. Updated.
– Brian
Aug 24 at 13:42
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
There is no need to search the table of moderators. Just index it directly with the name.
– lhf
Aug 24 at 12:27