How to get the dictionaries in a dictionary?

[Solved was retracted, I got lost in my code and found the real error]

Heres my code:

Config["Questions"] = {
	["Receptionist"] = {
		"How active are you? (1-10)",
		"How good is your grammar? (1-10)",
		"What does this position do?",
		"Why would you like to work here?",
	},
	["Security"] = {
		"How active are you? (1-10)",
		"How good is your grammar? (1-10)",
		"What does this position do?",
		"Why would you like to work here?",
	},
	["Shift Manager"] = {
		"How active are you? (1-10)",
		"How good is your grammar? (1-10)",
		"What does this position do?",
		"Why would you like to work here?",
		"What are you, (LR, MR, HR) and why?",
		"You understand trolling is no way acceptable.",
	},
} 
print(#config["Questions"])

It prints “0” when there are things in the dictionary. How would I get how many dictionaries are inside the questions dictionary?..

It should be just as simple as you would with a table. If I am not mistaken…

local Amount = #dictionary
1 Like

Sorry, I fixed the title. I didnt mean to say amount haha. :slight_smile:

Oops, I was correct. I just had an error in my code that wasnt actually erroring. Sorry!

2 Likes

is there anyway to print the dictionary title?

 ["AnotherDictionary"] = {
  "More",
  "Strings",
  "In",
      "Here",
},

Could you print “AnotherDictionary” ?

1 Like

My actual problem is edited for the repost, I got lost in my code heh…

You have to iterate through all the keys and count them yourself. There’s no way around it.

You can always keep track of the length yourself so you don’t have to keep counting every time you need its length. +1 when you’re inserting a new key, -1 when you’re removing a key.

1 Like

The problem with that is, I’m not the one making the dictionaries therefore my module wont know how many there are, but I guess you solved it. :3

Are there any alternatives other than using dictionaries?..

Can you clarify what the problem was with counting the number of keys in the dictionary? This is the code for doing that, btw:

local function countKeysInDict(dict)
    local count = 0
    for _, _ in next, dict do
        count = count+1
    end
    return count
end

Calling this on a table will count the number of keys in it.

3 Likes