0
\$\begingroup\$

I am attempting to implement an auto-save feature into a mobile game. I have the following code writing to the save file:

function saveFunc(input)
local saveData=input
local file = io.open( "saveFile.txt", "w" )

for i,val in ipairs(saveTable) do
    saveData=saveData.."\n"..val
end

file:write( saveData )
io.close( file )
end

This writes to the file correctly. The problem is that after the function finishes, the whole app restarts. Watching the output console, it re-prints the "Copyright (C)..." as if I had Relaunched the app.

I know it is this specific function because if I comment out the call for this function the game continues as normal. I also tried commenting out the io.close(file) but the program still restarted.

How can I write to a file and not restart the app?

\$\endgroup\$
0
\$\begingroup\$

The code used is saving the document to the local folder. This means that every update of that file will re-launch the app (at least in the emulator). To prevent this, save to system.DocumentsDirectory like so:

local file = io.open(system.pathForFile("pokedex.txt", system.DocumentsDirectory), "w" )
\$\endgroup\$
0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .