I'm working on a game (in libGDX) that would allow multiple player accounts. I need to store some simple user data (several key-value pairs). I think JSON is the best for my needs, but I'm wondering how this data should be organised. I'm thinking about two possibilities:

  • single file for each player seems better design-wise, but I'm not sure if real-time file creation won't lead to issues
  • one big file with player id as key and organised array of values - safer, but would require loading data for all players on initial read and each update (although there shouldn't be that many accounts on a single game instance). Also harder to maintain due to necessity of keeping values in proper order, etc.

Perhaps there are better ways to do it, that I didn't think about.


1 Answer 1


Storing all player profiles in a single file wouldn't be such a bad idea if it didn't mean you'd have to rewrite the file every time data was modified, even if just for a single profile. Having profiles stored in their own files, and perhaps in a player folder, would be a better option.

Here's some possible steps one could take to manage profile data:

  1. Load all profiles when the profile selection screen is active.
  2. Save the profile the player is playing on when they quit the game (or return to the main menu / profile selection screen).
  3. Create a repeating task to perform step 2 perhaps every minute. The interval depends on your game and your design choices.
  4. Create auto-save events that repeat step 2. Again, this depends on your game.
  5. Save all profiles when the game exits.

File architecture if you want to support multiple players with multiple profiles:

|-- Player 1
|   |-- Profile 1
|   |-- Profile 2
|   +-- Profile 3
+-- Player 2
    |-- Profile 1
    |-- Profile 2
    +-- Profile 3
  • \$\begingroup\$ Thanks to your suggestion I realised that if I limit the number of player accounts (which I guess should be done anyway) I can have the separate files for each account created in advance with default values and only assign them to newly created accounts. This would allow me to avoid real-time file creation. This means that I will certainly follow the separate files path. \$\endgroup\$ Jan 5, 2016 at 9:11
  • \$\begingroup\$ For what it's worth: Gdx.files.internal, that I was planning to use is read-only. You have to use Gdx.files.local, which cannot be prepared beforehand (i.e. available on compile time), so real-time creation is unavoidable. However Gdx.files.local is tailored for that, so I don't expect problems in this part anymore. \$\endgroup\$ Jan 13, 2016 at 22:15

You must log in to answer this question.

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