Help with dictionary key name

I want to use a string, something.Name as the name of a key in my dictionary. I went about doing this:

local name = "ramongUS"
local val = 4
local coolTable = {}
local dictionary = {name = 4}
table.insert(coolTable, dictionary)
print(coolTable["ramongUS"])
print(coolTable[1])

As a practice, but the last print only works, and my key’s name is “name”, not ramongUS, I want its name to be “ramongUS”. You might be thinking that is is unnecessary, because I can just set the name as the key, but the situation im going to be using this in is when you don’t always know the name of something, im looping through a folder that have children that can have different names or values.
I tried using name, a variable storing the name of the thing I want, but it won’t work. Is there anything I can do to set a string stored in a variable and set it as the name for a key in a dictionary?

local name = "ramongUS"
local val = 4
local coolTable = {}
local dictionary = {}
dictionary[name] = val
coolTable[name] = dictionary
print(coolTable["ramongUS"]["ramongUS"])

This should work as you want it to.

1 Like