The simplest way IMO is to save the data locally into a json file. You would overwrite the json file whenever is appropriate for your app (e.g. if you beat the score on a level), and I usually make a point of saving when the app exits or suspends too.
Then you would load the data when your app starts.
Rob Miracle posted a helpful file to github: http://developer.coronalabs.com/code/super-simple-lua-table-save-and-load-file-functions
If you require this file, then you will be able to call it’s “loadTable” and “saveTable” functions like so:
local loadsave = require("loadsave.lua") --when you need to save the data if currentScore \> highScores[currentLevel] then highScores[currentLevel] = currentScore loadsave.saveTable(highScores, "highScores.json", system.DocumentsDirectory) end --and when you need to load the data (e.g. at startup) highScores = loadsave.loadTable("highScores.json", system.DocumentsDirectory)
Obviously you’ll need to fiddle around with that so that it fits your needs, but that’s really all there is to it.
One thing that’s it’s worth keeping in mind is that your app cannot be built with files in the documents directory, so the very first time you try to load the table it will return nil. A simple solution is to use a quick if statement to create a new table if one doesn’t exist yet:
highScores = loadsave.loadTable("highScores.json", system.DocumentsDirectory) if highScores == nil then --no table was found so create one highScores = {} --and populate it with default data for i = 1, totalNumberOfLevels do highScores[i] = 0 end --might as well save the default table ready for next time loadsave.saveTable(highScores, "highScores.json", system.DocumentsDirectory) end