Can you put a number in a dictionary?

Hi, can you put numbers in a dictionary, like this: local MyDictionary = {10 = "Test"}?

wrong catagory, but no, a dictionary is for putting variables, but you can put the value as a number

2 Likes

it should be in scripting support

1 Like

As a key?
For dictionaries, yes, you can still use numbers as keys, but it would turn into a mixed table instead. if it’s purely numbers, it would be a numbered array instead.

Remember to use these brackets for each keys: []

As a value?
Definitely possible.

4 Likes

Actually, you can.

local myDict = {
    [1] = 'Test',
    [2] = 'Test2?'
}
myDict[3] = 'TestNumber3' -- to insert a key with value
myDict[900] = 'Haha'

print(myDict[3], myDict[1])

for k, v in ipairs(myDict) do
    print(k, v)
end
-- omg where's the 900

for k, v in pairs(myDict) do
    print(k, v)
end
-- okay that's more like it, got all the keys

and this is still as a dictionnary and not array based with indexes

3 Likes