Hello,
My loading and saving function works perfectly in the simulator, but fails on my Galaxy S5. Specifically, the game works fine on the first run, before anything is saved. Then, after I win a level, the game saves a higher value to the system file. After exiting the game and then opening it again, I get a black screen. I’ve pasted the code for my “main” file, which does the loading. I didn’t think it would be helpful to include the code in the “game” file that does the saving.
Thank you in advance for any insight.
local composer = require "composer" local myData = require( "annexoCodeFiles.annexoData" ) local json = require("json") local compPlayer = myData.compPlayer local unlockedLevels = {1,4} local jsonString = json.encode(unlockedLevels) -- Load Data -- Path for the file to read local path = system.pathForFile( "annexoFile.txt", system.DocumentsDirectory ) -- Open the file handle local file, errorString = io.open( path, "r" ) if not file then -- Error occurred; output the cause print( "File error: " .. errorString ) else -- Read data from file local preUnlock = file:read( "\*a" ) unlockedLevels = json.decode( preUnlock ) -- Output the file contents --print( "Contents of " .. path .. "\n" .. jsonString ) -- Close the file handle io.close( file ) end file = nil -- Save Data function saveData () -- Path for the file to write local path = system.pathForFile( "annexoFile.txt", system.DocumentsDirectory ) -- Open the file handle local file, errorString = io.open( path, "w" ) if not file then -- Error occurred; output the cause print( "File error: " .. errorString ) else -- Write data to file file:write( jsonString ) -- Close the file handle io.close( file ) end file = nil end saveData()