i’m trying to save the highscores in my game with it…
I’m doing everything according to how it should be - and it work. In the simulator it saves the scores perfectly, even when I restart it, it still knows what the old scores were…
On the device however, the scores are refreshed every time I restart the app…
Where are you saving the scores to? system.ResourcesDirectory or system.DocumentsDirectory? Do you by any chance have a difference in the filenames as far as case sensitivity is concerned?
if(isArcade) then
Data.lastscore_arcade= gameScore
local stringified=json.encode(Data)
file= io.open(path,“w”)
file:write(stringified)
io.close(file)
newHighScore=false
if(Data.highscore_arcade~=nil) then
if(Data.lastscore_arcade>Data.highscore_arcade) and (Data.lastscore_arcade>0) then
Data.highscore_arcade = Data.lastscore_arcade
local stringified=json.encode(Data)
file= io.open(path,“w”)
file:write(stringified)
io.close(file)
newHighScore=true
end
else
Data.highscore_arcade = Data.lastscore_arcade
if(Data.highscore_arcade>0) then
local stringified=json.encode(Data)
file= io.open(path,“w”)
file:write(stringified)
io.close(file)
newHighScore=true
else
Data.highscore_arcade=0
newHighScore=false
end
end
else
Data.lastscore_time= gameScore
local stringified=json.encode(Data)
file= io.open(path,“w”)
file:write(stringified)
io.close(file)
newHighScore=false
if(Data.highscore_time~=nil) then
if(Data.lastscore_time>Data.highscore_time) and (Data.lastscore_time>0) then
Data.highscore_time = Data.lastscore_time
local stringified=json.encode(Data)
file= io.open(path,“w”)
file:write(stringified)
io.close(file)
newHighScore=true
end
else
Data.highscore_time = Data.lastscore_time
if(Data.highscore_time>0) then
local stringified=json.encode(Data)
file= io.open(path,“w”)
file:write(stringified)
io.close(file)
newHighScore=true
else
Data.highscore_time=0
newHighScore=false
end
end
end
I tried both with the save/load functions you suggested in the article, and without them, but it made no difference
been using several methods which didnt work and gave me errors, but finally tried this one and it did the trick -
path= system.pathForFile(“LMData.json”, system.DocumentsDirectory)
local contents = “”
Data = {}
file = io.open( path, “r” )
if file then
local contents = file:read( “*a” )
Data = json.decode(contents);
io.close( file )
end
Where are you saving the scores to? system.ResourcesDirectory or system.DocumentsDirectory? Do you by any chance have a difference in the filenames as far as case sensitivity is concerned?
if(isArcade) then
Data.lastscore_arcade= gameScore
local stringified=json.encode(Data)
file= io.open(path,“w”)
file:write(stringified)
io.close(file)
newHighScore=false
if(Data.highscore_arcade~=nil) then
if(Data.lastscore_arcade>Data.highscore_arcade) and (Data.lastscore_arcade>0) then
Data.highscore_arcade = Data.lastscore_arcade
local stringified=json.encode(Data)
file= io.open(path,“w”)
file:write(stringified)
io.close(file)
newHighScore=true
end
else
Data.highscore_arcade = Data.lastscore_arcade
if(Data.highscore_arcade>0) then
local stringified=json.encode(Data)
file= io.open(path,“w”)
file:write(stringified)
io.close(file)
newHighScore=true
else
Data.highscore_arcade=0
newHighScore=false
end
end
else
Data.lastscore_time= gameScore
local stringified=json.encode(Data)
file= io.open(path,“w”)
file:write(stringified)
io.close(file)
newHighScore=false
if(Data.highscore_time~=nil) then
if(Data.lastscore_time>Data.highscore_time) and (Data.lastscore_time>0) then
Data.highscore_time = Data.lastscore_time
local stringified=json.encode(Data)
file= io.open(path,“w”)
file:write(stringified)
io.close(file)
newHighScore=true
end
else
Data.highscore_time = Data.lastscore_time
if(Data.highscore_time>0) then
local stringified=json.encode(Data)
file= io.open(path,“w”)
file:write(stringified)
io.close(file)
newHighScore=true
else
Data.highscore_time=0
newHighScore=false
end
end
end
I tried both with the save/load functions you suggested in the article, and without them, but it made no difference
been using several methods which didnt work and gave me errors, but finally tried this one and it did the trick -
path= system.pathForFile(“LMData.json”, system.DocumentsDirectory)
local contents = “”
Data = {}
file = io.open( path, “r” )
if file then
local contents = file:read( “*a” )
Data = json.decode(contents);
io.close( file )
end