Keeping save state even after quitting the app?

Hi all!

I am trying to create a game using Corona on Android but met some problem. For my game I have a level select which is similar to Angry Bird, where U will have to unlock it stage by stage but my problem is that after I quit my app(closing the whole application) the save state is all gone. I want it to save the level so that I can play it from where I left.

This means that I need to play from level 1 every time i close the application. Can someone help me to solve this problem?? 

I am using this load and save.lua file

https://github.com/robmiracle/Simple-Table-Load-Save-Functions-for-Corona-SDK

Thank You

When your app starts, try and load the table.

If the table equals nil, then it must be the first ever run of the app, so you need to create a new table. If it doesn’t equal nil, then the app will carry on with the saved data you just loaded.

@nick

I am still hv problem with this.

Below is my GameData Code

---------- M = {}; loadsave = require("loadsave"); local DATA\_FILE = "mygamesettings.json"; M.saveData = function() loadsave.saveTable(M.myTable, DATA\_FILE); end M.myTable = loadsave.loadTable(DATA\_FILE) -- this load myTable everytime I open the app local numOfWorlds = 2 local numOfLevels = 8 function M.GetNumOfWorlds() return numOfWorlds end function M.GetNumOfLevels() return numOfLevels end --if (M.myTable == nil) then M.myTable = {} M.myTable.levelData = {} for i=1,numOfWorlds do M.myTable.levelData[i] = {} for j=1,numOfLevels do M.myTable.levelData[i][j] = {} M.myTable.levelData[i][j].locked = true M.myTable.levelData[i][j].stars = 0 end end M.myTable.levelData[1][1].locked = false M.saveData() --end for j=1,numOfLevels do M.myTable.levelData[1][j].locked = false end M.myTable.levelData[1][2].locked = true M.myTable.levelData[1][3].locked = true M.myTable.levelData[1][4].locked = true M.myTable.levelData[1][5].locked = true M.myTable.levelData[1][6].locked = true M.myTable.levelData[1][7].locked = true M.myTable.levelData[1][8].locked = true return M;

M.saveData = function() loadsave.saveTable(M.myTable, DATA\_FILE); end M.myTable = loadsave.loadTable(DATA\_FILE) -- this load myTable everytime I open the app

Here is where I save and load the table

It still does not load the stage that I played before.

Can you help me to check where is it going wrong or guide me through this? (Btw i am using the Corona Simulator)

Thank You

So now I am able to save the level state in my “mygamesettings.json” but I cant seems to be able to load the saved file at the start of the application.
For my game I have a scenetemplate where I put all the levels in. For my saveTable i placed it at the “enterscene”
Where am I suppose to place my loadTable code??
Please tell me if you guys need any more codes.
Anyone can help?? Please…

One more question:How should my load function look like? LoadTable(), or loadsave.loadTable()???

Someone or Anyone can help???

Really need help with this.

Help is greatly appreciated.

Bumps.
Need some help over here
Thanks

I’ve put together an example of how to use both the GGData library and DMC Autostore.

http://www.otterstudios.co.uk/Saving.zip

Is there any other method that I can use with the codes above??(editing the codes above)

I am now lacking the loading part. I played through the levels and my json file was saved, when relaunched, the saved file is still there but when I press start, it loads the default table again…

Anyways thanks for the help, will study the example that you provided!! 

Thanks Nick!

@Rob Miracle
Rob could you lens some help or advice here??
Im using the load save lua that is provided by you but I cant seems to get it to work.

Bumps

When your app starts, try and load the table.

If the table equals nil, then it must be the first ever run of the app, so you need to create a new table. If it doesn’t equal nil, then the app will carry on with the saved data you just loaded.

@nick

I am still hv problem with this.

Below is my GameData Code

---------- M = {}; loadsave = require("loadsave"); local DATA\_FILE = "mygamesettings.json"; M.saveData = function() loadsave.saveTable(M.myTable, DATA\_FILE); end M.myTable = loadsave.loadTable(DATA\_FILE) -- this load myTable everytime I open the app local numOfWorlds = 2 local numOfLevels = 8 function M.GetNumOfWorlds() return numOfWorlds end function M.GetNumOfLevels() return numOfLevels end --if (M.myTable == nil) then M.myTable = {} M.myTable.levelData = {} for i=1,numOfWorlds do M.myTable.levelData[i] = {} for j=1,numOfLevels do M.myTable.levelData[i][j] = {} M.myTable.levelData[i][j].locked = true M.myTable.levelData[i][j].stars = 0 end end M.myTable.levelData[1][1].locked = false M.saveData() --end for j=1,numOfLevels do M.myTable.levelData[1][j].locked = false end M.myTable.levelData[1][2].locked = true M.myTable.levelData[1][3].locked = true M.myTable.levelData[1][4].locked = true M.myTable.levelData[1][5].locked = true M.myTable.levelData[1][6].locked = true M.myTable.levelData[1][7].locked = true M.myTable.levelData[1][8].locked = true return M;

M.saveData = function() loadsave.saveTable(M.myTable, DATA\_FILE); end M.myTable = loadsave.loadTable(DATA\_FILE) -- this load myTable everytime I open the app

Here is where I save and load the table

It still does not load the stage that I played before.

Can you help me to check where is it going wrong or guide me through this? (Btw i am using the Corona Simulator)

Thank You

So now I am able to save the level state in my “mygamesettings.json” but I cant seems to be able to load the saved file at the start of the application.
For my game I have a scenetemplate where I put all the levels in. For my saveTable i placed it at the “enterscene”
Where am I suppose to place my loadTable code??
Please tell me if you guys need any more codes.
Anyone can help?? Please…

One more question:How should my load function look like? LoadTable(), or loadsave.loadTable()???

Someone or Anyone can help???

Really need help with this.

Help is greatly appreciated.

Bumps.
Need some help over here
Thanks

I’ve put together an example of how to use both the GGData library and DMC Autostore.

http://www.otterstudios.co.uk/Saving.zip

Is there any other method that I can use with the codes above??(editing the codes above)

I am now lacking the loading part. I played through the levels and my json file was saved, when relaunched, the saved file is still there but when I press start, it loads the default table again…

Anyways thanks for the help, will study the example that you provided!! 

Thanks Nick!

@Rob Miracle
Rob could you lens some help or advice here??
Im using the load save lua that is provided by you but I cant seems to get it to work.

Bumps