Hello! I’m having trouble finding an easy answer for this, and i’ve searched for one, but i can’t find any specific answers. Could just be asking the wrong question… but, how would I go about retrieving the number of a key in a dictionary when the key is a string value, and this would need to be doable in a layered dictionary with dictionaries in dictionaries.
for instance:
dictionary = {
[“Dog”] = { --I want to find the number of this key here which would be 1.
[“Dog’s snout”] = true,
},
[“Cat”] = {
[“Cat’s tail”] = true,
}
}
My reasoning for needing this is for deserialization, so i need to be able to retrieve the key’s number to match it with an keyid that’s serialized and saved in a datastore, so i wouldn’t necessarily know that i’m looking for “Dog”
I’d need to loop through, and discover the key’s order in side each dictionary, and match with the datastore.
This is a physical example of the code i’m using (which i’m using the Datastore2 module)
Basically, previously, when the game loaded, i looped through the actual default data value dictionary to get all the names of the values and put them in a seperate key dictionary for later comparison with the deserialized key ids. The circled part is where I would loop through the inside table loaded in the dictionary. But again, to be clear i need to find the number order value of ‘i’ which in this case will instead give me a string name of whatever item i’m fetching.
In some of the other stores, i only need to save one dictionary, so i dont have to go the extra mile by creating nested dictionaries. But this one i do. WIth the other tables that are created. In the other more basic stores, the for loop will detect ‘i’ as the key’s number since it does not have a value of a table, but in this more complex one, the for loop will detect ‘i’ as the name of the table instead of the key’s order. So i need to find the number of the key without getting the name.
i’m wondering if i can do three variables then? like
for num,i,v in pairs(dictionary) do
end
?
would that work?
I don’t know. Any help would be much appreciated. Thankyou for reading!
-Manelin