developa Posted July 21, 2017 Share Posted July 21, 2017 Hello, how to detect second table in the first one? For example: commands={} commands["value"] = { ["report"] = { -- How to detect the name of this 'report'? [1] = "report", [2] = "notification" }, ["checkAdmins"] = { [1] = "admins" [2] = "administration" } } for _,value in ipairs(commands["value"]) do for _,v in ipairs(value) do if(value=="report")then addCommandHandler(v[1], report) elseif(value=="checkAdmins")then addCommandHandler(v[1], checkAdmins) end end end Link to comment
TRtam Posted July 22, 2017 Share Posted July 22, 2017 for type,data in ipairs(commands["value"]) do if type == "report" then addCommandHandler(data[1], report) elseif type == "checkAdmins" then addCommandHandler(data[1], checkAdmins) end end The first value of the ipairs/pairs will be the keyname and the second will be the value 1 Link to comment
developa Posted July 22, 2017 Author Share Posted July 22, 2017 (edited) This example does not work. Edited July 22, 2017 by developa Link to comment
TRtam Posted July 22, 2017 Share Posted July 22, 2017 Sorry I was wrong. You need to use pairs () to get the keyname and the value for type,value in pairs(commands["value"]) do for _,value in pairs(value) do if type == "report" then addCommandHandler(value, report) elseif type == "checkAdmins" then addCommandHandler(value, checkAdmins) end end end 1 Link to comment
developa Posted July 22, 2017 Author Share Posted July 22, 2017 (edited) 23 minutes ago, saygoodbye said: Sorry I was wrong. You need to use pairs () to get the keyname and the value for type,value in pairs(commands["value"]) do for _,value in pairs(value) do if type == "report" then addCommandHandler(value, report) elseif type == "checkAdmins" then addCommandHandler(value, checkAdmins) end end end Thanks! SOLVED Edited July 22, 2017 by developa Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now