local States = {
["United States"] = 50,
["Netherlands"] = 12
}
print(States[2])
Returns nil
. Does anyone know why? I really don’t see anything wrong with it.
local States = {
["United States"] = 50,
["Netherlands"] = 12
}
print(States[2])
Returns nil
. Does anyone know why? I really don’t see anything wrong with it.
The table <%States%> is a dictionary, NOT an array.
An array is just a sorted list of objects. A dictionary stores key-value pairs.
If you were trying to access the value &12 by indexing the second element in the State’s table, your table would have to look like this:
local States = {50, 12}
print(States[2]) -- Prints 12 to the output
However, if you are trying to access the value &12 by using the respective key your table would look like this AND you index it like this:
local States = {
["United States"] = 50,
["Netherlands"] = 12
}
print(States.Netherlands) -- Prints 12 to the output