First off, I’ll post my chunk of code that utilizes the “Table LoadSave” function found here , I think it was done by Rob…
I have the required ‘loadsave’ module also declared above this code chunk so that’s not the issue.
-------------- Updated ----------
local myHighScores = {} local function bestScoreLoadSave() local path = system.pathForFile( "saveTest33.json" , system.DocumentsDirectory ) local file = io.open( path, "r" ) if (file) then myHighScores = loadsave.loadTable("saveTest33.json", system.DocumentsDirectory) loadsave.printTable(myHighScores) end if myHighScores[score.currentLevel] == nil then myHighScores[score.currentLevel] = 0 end if myHighScores[score.currentLevel] \< score[score.currentLevel] then myHighScores[score.currentLevel] = score[score.currentLevel] loadsave.saveTable(score,"saveTest33.json", system.DocumentsDirectory) end end bestScoreLoadSave()
So what this is doing is printing:
Dec 29 19:44:17.658: table: 0x608000e63800 {
Dec 29 19:44:17.658: [currentLevel] => 2
Dec 29 19:44:17.658: [2] => 65.1
Dec 29 19:44:17.658: }
So it’s printing the correct values - but when it gets to:
if myHighScores[score.currentLevel] == nil then myHighScores[score.currentLevel] = 0 end
it’s always reverting to 0. But in above example - “myHighScores[score.currentLevel]” should = 65.1… but it’s saying that it’s nil and making it 0…
Am I accessing the table correctly?
Ahh OK finally figured this out, the last part:
loadsave.saveTable(score,"saveTest33.json", system.DocumentsDirectory)
I should have been saving the HighScores table not the score table… <RESOLVED>