Hi,
I have the following code:
local filePath = system.pathForFile( "data.txt", system.DocumentsDirectory ) local file local reason local highscore local localScore = event.params.data; function loadHighScore() file, reason = io.open(filePath, "r" ) if file then -- read all contents of file into a string highscore = file:read( "\*a" ) else file = io.open( filePath, "w" ) file:write(0) highscore=localScore end io.close( file ) end function saveHighScore() file = io.open( filePath, "w" ) file:write(localScore) end loadHighScore()
So basically I load the highscore and it checks for a file, if the file doesn’t exist it creates a new one and makes the highscore the same as the local score… the next time it does this, the file WILL exist so it takes the highscore from the file and shows them that.
This works perfectly in the simulator but on devices it never seems to actually write the file, meaning the highscore is always reset.
I did have this set as the resourceDirectory which worked however I found that was a bad idea as when I updated the app it would be reset.
Why is this not working? My permissions are:
usesPermissions = { "android.permission.INTERNET", "android.permission.ACCESS\_NETWORK\_STATE", "com.android.vending.CHECK\_LICENSE", "android.permission.WRITE\_EXTERNAL\_STORAGE", "android.permission.READ\_PHONE\_STATE" },
Thanks
Kevin