I am writing a text to table encoder and while implementing array logic I came across some pretty strage behavior.
local t = {{},{},[3] = true, {}, {}, {}} print(t) t[6].something = true
In this example I create an array containing 6 members (5 tables and one boolean).
Instead of stepping over the direct assignment at 3rd index, the array just overrides it.
Here is the output:
My guess is that there is some kind of internal index counter that starts at index 1 no matter what, marches its way through the array replacing all. And it is activated the second there is a single non-dictionary assigned value.
Well thats probably exactly what’s going on, im not expecting any solutions. I wanted to document this for anybody else looking for answers YKWIS .
When creating a table, it seems to prioritise the non-key-worded values (the array portion) first, then goes back and deals with key-worded values (akin to a dictionary).
I can’t find where, but on the wiki somewhere it does tell you not to use number’s as keys in a dictionary, when the dictionary is also anarray (like what you are trying to do)
{} > [1]
{} > [2]
[3] = true > index 3 is set to true
remaining 3 elements continue from the last sequential index
idk where the remaining 3 would possibly be indexed at but im guessing they are shifted down 1
If you read my post you would see that that’s not the case. 3 does get set to true but is overriden by {} afterwards. I have also noticed that arrays don’t seem to have a priority:
Alr I tested it last time and the conclusion is that the elements are asigned one by one based on their order in the “lua declaration code”. Both values can overridde each other.