How to future proof an app? ( in term game settings file between game updates)

Hi guys.

My app is not yet finished but I would think past the first release. What i am trying to figure is what happened if I need to release an updated version in the future. Specifically what happened to the player high score, achievements and so on.

I am using JSON (with data.lua found on this forum) and a gameSettings table to save the player info, game settings like sound and so. Something like this (in main.lua):

[lua]_G.gameSettings = { }

_G.gameSettings =
{
[“gameVersion”] = 1,
[“hiScore”] = 0,
[“score”] = 0,
[“musicOn”] = true,
[“fxOn”] = true,
[“fxOn”] = true,
[“isGameActive”] = true,
[“isGameSaved”] = false,
[“gameLevel”] = 3,

– and so on

data.saveSettings() – I THEN SAVE the global _g.gameSettings (from data.lua)[/lua]

The real question, is how you guys would approach updating a app later that may need a different structure for gameSettings table? For instance let say I need to add a feature like local multiple player and so need to keep track of more than one player highscore (just an example) In that case, the gameSettings will need to change to accomodate the extra players data. Something like:

[lua] _G.gameSettings =
{
[“gameVersion”] = 1,
[“hiScore”] = {0,0} – for a second player

}[/lua]

I may also want to add a player name like [“name”] and so on. Of course if I know in advance what future version I may build I could simply add them now (and I will) But what about variables that I cannot think about right now?

Obviously I cannot just change the gameSettings table for version 2.0 of the game since it would screwed up everybody who has used version 1.0.

I was thinking maybe having temporary variables like [“v1”], [“v2”] but that’s not very elegant! Also I am not sure how I can predict if for instance [“v1”] will be a simple variable or an actual table like [“v1”] = {123,123,123}

How do you guys deal with such problem?

Thanks in advance for any pointers.

Mo.

[import]uid: 49236 topic_id: 16437 reply_id: 316437[/import]

Well one of the beauties of using JSON to store your settings with is that as long as you maintain the variables you no longer use and just add new things, you will be reasonably future proof.

Lets say your settings are something like:

settings[“score”] = playerScore

and later you want to store a table of scores, just add a new member to the table:

setting[“scores”] = multiPlayerScores

and just stop using the “score” member.

And as long as your new version properly initializes values not in the settings file, then you shouldn’t run into problems.

Your settings file/table ends up with some junk over time, but if it becomes a problem, you can always put in logic to remove old members once the new version runs.
[import]uid: 19626 topic_id: 16437 reply_id: 61380[/import]

THANKS so much robmiracle for your fast response!

So if I understand you correctly, if I change my gameSettings to:
[lua] _G.gameSettings =
{
[“gameVersion”] = 1,
[“hiScore”] = 0,
[“score”] = 0,

[“scores”] = {0,0}
}[/lua]

I should be ok? So all I will need to do is change the logic in my game to use gameSettings.scores[1] and gameSettings.scores[2] for say 2 players instead of one.

BUT,

1- Would the original file (where the gameSettings is saved in Json format) be “unreadable” since we are adding a new variable to the file?

2- How you would you transfer the previous original score (game version 1.0 ) to the new score table? I guess I could simply do
gameSettings.scores[1] = score?! But you do not want to have that at each app start!

I am sorry If I am not making sense here. I am trying to setup my file correctly so I will not have issues later.

Thanks again for a great insight!

Mo

[import]uid: 49236 topic_id: 16437 reply_id: 61384[/import]

When you read the file in and json.decode() it, you get a table that has all of the variables that were in the JSON file.

Now in your loadSettings function or loadScores or whatever, after you read the file in, you’re going to do something like:

[lua]if settings[“scores”] == nil then
settings[“scores”] = {0,0}
end[/lua]

or if you want to transfer “score” to “scores”:

[lua]if settings[“score”] == nil then
– never saved the original score file
settings[“scores”] = 0
end
if settings[“scores”] == nil then
settings[“scores”] = {score,0}
end[/lua]
You’re settings/score logic should always test to make sure the settings are there and if they are not, initialize them.
[import]uid: 19626 topic_id: 16437 reply_id: 61385[/import]

That’s make a lot sense. Thanks robmiracle! I appreciate it and I feel much better in the issue of future update.

You rock!

Mo [import]uid: 49236 topic_id: 16437 reply_id: 61389[/import]