Tables are both Arrays and Dictionaries, they can hold multiple datatypes and are really useful.
They have an “index” and a “value”, when you do something like: table[index] it’ll give you the value of that index.
Arrays
Arrays have ordered indexes starting from 1 to how ever many you give, in arrays you do not give the index - instead it gives the index itself.
An array will look like:
local Array = {3,2,1}
Loop through this and you’ll see how they’re ordered:
for index, value in pairs(Array) do
print(string.format("%d | %d", index, value))
end
--[[
1 | 3
2 | 2
3 | 1
]]
Dictionaries
In Dictionaries you give the index, they’re not ordered.
A Dictionary will look like:
Protip: If at all possible, don’t use mixed tables. In other words, use it as either a dictionary or as an array. While there are a few odd scenarios where using a mixed table works well, the vast majority of solutions are much easier to program around having a more rigid structure & will save you from weird bugs regarding iteration.
You seem to understand what a dictionarry actually is, but what’s confusing is when people call dictionarries tables. “Logically” speaking they are indeed called dictionarries, but it’s not really a problem to call them tables, because after all dictionarries are really just a special type of tables.
Well I’m not sure about what return said: the fact that arrays and dictionarries both fall on the table category. So basically an array is a table, and a dictionarry is a table. In my mind I always had the idea that table is just a synonym of array, and dictionarries are basically just tables but have a different way of organazing. Because after all, some other languages call arrays something different from tables, in python arrays are also called lists. Array is the universally accepted name, that might be different in other languages
pairs doesn’t guarantee ordered iteration and it is meant for iteration where the key is arbitrary or unknown. Use ipairs to iterate through arrays, always. ipairs iterates at an i++ basis and is designed for working with arrays.
The output of your dictionary iteration is also incorrect. You put the values of the indexes in descending order rather than matching their index (I3 has a value of 1 but you put 3 in the output comment).