3

I'm writing a game for Android. When the user completes a level, they can restart from the next level if they lose (i.e. I need to store an integer to remember which level they got to). If the app is interrupted during play, I save the world state to disk (this is complex state storing a map and game entities).

I'd like to keep my options open in the future for changing my game code and the way the world state is saved/stored. However, I must consider the scenario when a user has an old version of the world state on their phone because they were in the middle of a game, they upgrade the app and now the app cannot load the world state.

Having to write code to migrate the old version of the data to the new version of the data would be a pain if there's some way I can avoid this. It would be nice if I could somehow ask the user to finish their current game in progress before updating. Can this be done? Are there any other options?

I don't intend to do this often. I'd like to iteratively develop my game while getting some early feedback, but this is difficult if I must fix how the world state is saved and restored now.

I hope this doesn't seem a silly question, but on a PC or a console it's perfectly OK to have games that you cannot save during a game or you can only save between levels. I'm just finding Android a bit of a pain here as you must have a save game strategy for all games.

RichardNewton
  • 876
  • 1
  • 12
  • 20

1 Answers1

2

You cannot prevent a user from upgrading an app, and you cannot execute any code until your app is installed (or upgraded).

Quite frankly, losing data due to an upgrade is unacceptable. If you use an SQLiteOpenHelper, you automatically get nice hooks that help you with the upgrade process.

I understand that you have a pretty complex savegame setup, but try to keep it as flexible as possible to allow for easy upgrades. There are lots of techniques that help you with that.

And Android and PCs are just completely different - on a PC, you sit down and play for hours. On Android, you play real quick and then do something else. Or, you play and get a phone call and are forced to switch away from your game.

EboMike
  • 76,846
  • 14
  • 164
  • 167
  • "I understand that you have a pretty complex savegame setup, but try to keep it as flexible as possible to allow for easy upgrades. There are lots of techniques that help you with that." Any pointers to the techniques you mean? – RichardNewton Nov 03 '10 at 01:54
  • That depends on what your savegame files look like. Are they binary? ASCII? What kind of data do they have? How do they store data? Values for arrays? Key/value pairs? etc. etc. etc.... you'd need to show specific parts of your savegame files that you think might be a problem after an upgrade. – EboMike Nov 03 '10 at 03:35
  • For example, each alien in the game has an x,y integer which is easy to store. Then it has a Behaviour object that tells the alien how to act e.g. new CombineBehaviour(new ShootAtEntity(PLAYER), new FlyInDirection(5, 5)) would combine a behaviour that makes the entity shoot at the player entity and a behaviour to fly in a fixed direction. These behaviour objects are all quite simple, just storing a few integers each and sometimes references to other entities. I'm using Java serialisation because I can't see any easy ways to convert my behaviour objects to e.g. XML. – RichardNewton Nov 03 '10 at 21:17
  • So what's a possible scenario you see that could cause incompatibilities? – EboMike Nov 03 '10 at 21:48
  • Say instead of CombineBehaviour taken two behaviours, I might want to generalise it to take a list of behaviours or perhaps I might add a parameter to FlyInDirection concerning how the entity should fly (e.g. in a straight line or zig zag). Of course, I could write code to migrate data from one representation to the other but it just requires more testing and means more coding. I hope you don't think I'm being silly but when writing a game on the PC, I didn't have to consider such issues and it meant I could be more aggressive about refactoring. I'm just considering all my options. – RichardNewton Nov 03 '10 at 22:36
  • By the way, I've been testing some of the most popular Android games and 90% of them lose your data if you put them in the background and then kill them with a task killer (i.e. so this is what would happen if they were killed when memory got low). I'm not saying that's OK, but that's what my competition is doing and they don't get any complaints about it. :-\ I've spent a huge amount of time planning my save/load strategy so this is pretty irritating. – RichardNewton Nov 04 '10 at 12:33
  • This is not PC vs Android - this is "do I allow for saving at any point or not". On PlayStation, I once added a Quick Save that saved the entire state to memory so you could restart if you messed up. It's a very nice service to the user, and doing that gives you the edge. Sure, you don't have to do it, but put yourself in the position of the player - do you want to lose all your progress if you get a random phone call? That would SUCK. – EboMike Nov 04 '10 at 16:17