Trouble with updating the game

Hello everyone. I have a problem with updating my game.
So, I created one and download it on my device. I did some stuff like : get a progress in there, reach some points.
After that I decide to improve some bugs in game. Then I build it with new version. Then download and install it on my device. Problem was - my save was discard and I need do again what I did earlier.
Question : how can I improve it - without discarding existing data and uploading my games right.
Thanks, have a good day.

It seems that you are not using a permanent storage option like writing to a file. Otherwise it shouldn’t be a problem. Have you looked into this -> https://docs.coronalabs.com/guide/data/readWriteFiles/index.html

If you did write to a file and it still discards data, you could share the part of the code that you use to save and load your progress.

From my experience, if you install an app over the existing one it doesn’t delete your local data. You don’t have to remove the old app to install the new one if that is what you were doing. :smile:

1 Like

Dear, im not delete previous version of app - i just INSTALL the update version for app.
How i do it:
1)Firstly i install first version of the game
2)I check it for bugs etc. When i find one i go to my source code and impove it
3)I build new version of the app and install it
4)When it was installed i cant see my previous data i see new one!
Maybe it helps you to directly help me

So, I use .json file type.
Maybe they rewrite because of they stored in game folder not in system directory?
This is my code:(p.s. this two functions stored in main.lua file)
function loadSettings(filename)
local path = system.pathForFile(filename, system.ResourseDirectory)
local contents = “”
local myTable = {}
local file = io.open(path, “r”)
if(file) then
contents = file:read("*a")
myTable = json.decode(contents)
io.close(file)
return myTable
end
return nil
end

function saveSettings(t, filename)
local path = system.pathForFile(filename, system.ResourseDirectory)
local file = io.open(path, "w")
if(file) then
    local contents = json.encode(t)
    file:write(contents)
    io.close(file)
    return true
else
    return false
end 
return nil
end

You can’t save to Resource Directory. On Android and iOS devices, that’s protected. You need to save to Documents Directory on actual devices.

1 Like

@fuji you can see more information about directories here and what @XeduR talks about in the sub section of that link I posted earlier -> https://docs.coronalabs.com/guide/data/readWriteFiles/index.html#directories

1 Like

@XeduR, thanks! I would try it! I hope it would be work properly as i want!

hi Fuji,

saving data on system.DocumentsDirectory will works well: you will not loose setting on installing again.

I suggest 2 point:

1 the setting file will not be there the first time the application is installed.
So think inside LoadSettings to a mechanism to write it with the parameters in defautl in case it is not there. Like this.

file: settings.game

local M = {}
    local json = require( "json" )
    local filePath = system.pathForFile( "settings.json", system.DocumentsDirectory )
    local settingsTable = {sound = true, soundFx = false, difficulty = 85, namePlayer ="Name player"}

    function M.loadSettings() 
        local file = io.open( filePath, "r" )
     
        if file then
            local contents = file:read( "*a" )
            io.close( file )
            settingsTable = json.decode( contents )
            -- for example a new settings not present on old config
            if settingsTable["namePlayer"] == nil then
              settingsTable["namePlayer"]="Name Player"
            end
        else
          -- create file settings, file doesn't exists
          M.saveSettings(settingsTable)
        end
        
        return settingsTable
     end
    
    function M.saveSettings(sTable)
    ...
    end

return M

so, when you call loadSettings you will in any case have some settings.

on file main:

local settingsGame = require("settingsGame") --game's settings

...
  -- Load settings Game
  settingTable = settingsGame.loadSettings()

2 if trying the program on the phone, everything freezes with a black screen, it’s because you forgot to enter the permissions on build.settings

   androidPermissions = {
     "Android.permission.WRITE_EXTERNAL_STORAGE"
   },

you can unlock everything without recompiling, going to manually set them in the phone settings on the app permissions.

the question of permission is not reported in the links above and not even in this, very well done: guide programming

I think it’s because this block was only recently introduced.

Ciao
Renato

1 Like

Sorry I found that androidPermissions is deprecated, use inside:

  android =
  {
    usesPermissions = {
      "android.permission.INTERNET",
      "android.permission.WRITE_EXTERNAL_STORAGE"
    },
  },

Renato

1 Like

Thanks Renato! It helps me! Now my files save and load as they need. Have a good time!