I have a dictionary indexed by numbers.
When sent to the client, the table THINKS that it’s indexed and thus remove number 6 and 10 (and my string index test!).
Here you can see my issue. It also adds a ‘void’ parameter to index 1. There was no item index 1 before.
I could convert all indexes to strings but that’s a workaround not a solution.
Mixed tables don’t make it through the client-server boundary. Same with metatables. You’ll need to either index differently or stick to one type of key.
I’m not gonna lie, that #1 got me as well. My assumption is maybe its starting at index #2. Anywho, you’re not limited to that. You could just forget the keys and just insert values into the table and index it in the value itself.
for i,v in ipairs(tbl) do
if v.ID == 1 then
-- we have key one
end
end
Note the use of ipairs here. The thing is since we’re omitting the key then the table order will always be from 1 to #tbl with no nil keys. And if you use table.insert or table.remove it will shift the entries accordingly.
If you wanted to loop through a table with mixed keys or missing keys then you could use pairs instead of ipairs.