I’m not sure what I changed that is causing this, but suddenly the numeric indexes of a table I’m saving with loadsave are being loaded by loadTable() as string keys. The data is correct at the time of being saved AND the data is successfully read in from that file, but the numeric keys become string keys.
That is, rather than this (which is expected):
data[1]
It is loading as:
data['1']
Which is obviously wrong. It makes things like ipairs() fail since after loading there are no numeric keys.
This is the filename code:
function level\_data.getFilename(category) return 'level\_data' .. category .. '.json' end
This is the loading code:
function level\_data.load(category) local data = loadsave.loadTable(level\_data.getFilename(category)) if not data then data = { category = category } end -- This is just a test; as of right now, this is not printing anything for k, v in ipairs(data) do print(k, v) end -- This one DOES print stuff, but the "numeric" keys are in random order (with -- category in the middle) since they are strings for k, v in pairs(data) do print(k, v) end -- This always prints zero print(#data) for level = 1, #levels[category], 1 do -- This condition is always firing since level is an integer but the -- table is being loaded with strings if not data[level] then data[level] = { unlocked = false } end end return data end
This is the saving code:
function level\_data.save(data) -- This always prints the correct number of levels in the data print(#data) loadsave.saveTable(data, level\_data.getFilename(data.category)) end
What’s going on? This has been working for me for a long time, I’m not sure why loadsave is suddenly doing this.