See the attached file.
Sometimes it show this type of error in simulator but its working fine in devices.
What will be the possible reason for this problem?
gamedata.lua file(error occur in this file)
local json = require(“json”)
local gameData = {}
local fileName = “gameData1.json”
function gameData.setGameData()
local gameData
local path = system.pathForFile( fileName, system.DocumentsDirectory )
local file = io.open( path, “r” )
if(file == nil) then
print(“first run”)
local path = system.pathForFile( fileName, system.ResourceDirectory )
local file = io.open( path, “r” )
local readData = file:read( “*a” )
gameData = json.decode(readData)
io.close( file )
file = nil
local path = system.pathForFile( fileName, system.DocumentsDirectory )
local file = io.open( path, “w” )
file:write( readData )
io.close( file )
file = nil
end
local path = system.pathForFile( fileName, system.DocumentsDirectory )
local file = io.open( path, “r” )
local readData = file:read( “*a” )
local gameData = json.decode(readData)
io.close( file )
file = nil
return gameData
end
function gameData.getGameData()
local path = system.pathForFile(fileName, system.DocumentsDirectory )
local file = io.open( path, “r” )
local readData = file:read( “*a” )
local gameData = json.decode(readData)
io.close( file )
file = nil
return gameData
end
function gameData.saveGameData(gameData)
local saveData = json.encode(gameData) –error occur here
local path = system.pathForFile( fileName, system.DocumentsDirectory )
local file = io.open( path, “w” )
file:write( saveData )
io.close( file )
file = nil
return true
end
return gameData