Sorry about the late reply
but put these functions in your main.lua:
[lua]
function Load( pathname )
local data = nil
local path = system.pathForFile( pathname…".json", system.DocumentsDirectory )
local fileHandle = io.open( path, “r” )
if fileHandle then
data = json.decode( fileHandle:read( “*a” ) or “” )
io.close( fileHandle )
end
return data
end
function Save( data, pathname )
local success = false
local path = system.pathForFile( pathname…".json", system.DocumentsDirectory )
local fileHandle = io.open( path, “w” )
if fileHandle and data then
local encodedData = json.encode(data)
fileHandle:write( encodedData )
io.close( fileHandle )
success = true
end
return success
end
[/lua]
So now you can do this to check if the scores file already exists, and if not, create one with a score of 0:
[lua]
local score = Load(“score”)
if score ~= nil then
--score file already exists
elseif score == nil then
--score file doesn’t exist…create one!
local score = 0
Save(score, “score”)
end
[/lua]
Now here is how you would edit the score:
[lua]
–to load the score data
local score = Load(“score”)
–to view the score data
print(score)
–to edit the score data (temporary until saved to file)
score = 10
–to save these edits to the file
Save(score, “score”)
[/lua]
Hope this helps! 