i have local Items = { Mining = {} }
i can do Items.Mining its tabel: some hex stuff
but Items[1] or #Items is nil.
local ShopData = { Mining = {} }
for i = 1, #ShopData do end
it will skip because shopdata is empty
So tables can act as arrays, or as unordered sets in lua. This means that there is a mode of some sort where things like #table
and table[1]
will work (though 1 can be a specific key, but I won't go into that). And another mode, which you are in, where they won't.
See this tutorial on lua for more information. What this all means is that you are setting a key
in your table as mining. That is separate from the "array" mode of the table that allows you to look through indexes (numbers that are accessed like shopData[1]
). It also means that #ShopData
will return the number zero. That's the number of array indexes.
To loop through an _unordered set of key and value pairs _ you will want to use the pairs
function.
for key, value in pairs(ShopData) do print(key, value) end
That would print something similar to.
Mining {}