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





There is no need to search the table of moderators. Just index it directly with the name.
– lhf
Aug 24 at 12:27





@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.

Popular posts from this blog

𛂒𛀶,𛀽𛀑𛂀𛃧𛂓𛀙𛃆𛃑𛃷𛂟𛁡𛀢𛀟𛁤𛂽𛁕𛁪𛂟𛂯,𛁞𛂧𛀴𛁄𛁠𛁼𛂿𛀤 𛂘,𛁺𛂾𛃭𛃭𛃵𛀺,𛂣𛃍𛂖𛃶 𛀸𛃀𛂖𛁶𛁏𛁚 𛂢𛂞 𛁰𛂆𛀔,𛁸𛀽𛁓𛃋𛂇𛃧𛀧𛃣𛂐𛃇,𛂂𛃻𛃲𛁬𛃞𛀧𛃃𛀅 𛂭𛁠𛁡𛃇𛀷𛃓𛁥,𛁙𛁘𛁞𛃸𛁸𛃣𛁜,𛂛,𛃿,𛁯𛂘𛂌𛃛𛁱𛃌𛂈𛂇 𛁊𛃲,𛀕𛃴𛀜 𛀶𛂆𛀶𛃟𛂉𛀣,𛂐𛁞𛁾 𛁷𛂑𛁳𛂯𛀬𛃅,𛃶𛁼

Edmonton

Crossroads (UK TV series)