Jump to content

table


developa

Recommended Posts

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

  • Like 1
Link to comment

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
  • Like 1
Link to comment
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 by developa
Link to comment

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...