Data Management

Hi there,

since i never made a mobile game i have no real experience how to do things the right/optimized way regarding performance, memory, read/write etc…

For instance, a game has lets say 5 worlds and each world has 600 levels. Now ofc i need to manage this data somewhow. This will contain things like level completion, level stars, level score, world completion, etc, all kind of stats.

What i have now is something like this(readability to me is not important, so only indexing) except i use 1 world = 1 file.

The file with 5 worlds a 600 levels is ~ 210K in filesize:

1 = -- world 1
  {
    1 = {0,0,0,0},  -- level 1 {score,stars,..}
    2 = {0,0,0,0},  -- level 2
    3 = ....        -- level 3
  },
2 = -- world 2
  { 
    1 = {0,0,0,0},  -- level 1 {score,stars,..}
    2 = {0,0,0,0},  -- level 2
    3 = ....        -- level 3
  },
3 = -- world 3
  {...}

So, what i want to know here

  1. Is it ok to save all the data in one file like above or should i better leave it at 1 world = 1 file?
  2. Can i load the file at the start of the game, keep it always in memory and do my read/write as needed? Or should i load/unload it everytime i need it? More than one screen will access the data.
  3. Is it good to use the simple sys.save and sys.load to handle this data? Maybe they are better ones?

I welcome anyone to share his experience.

  1. I would create individual files to be overall cleaner.
  2. Yes it should be fine to keep it always loaded. You may be overthinking optimization at this stage.
  3. Test and see if you hit the limits of these. If you do then you will need to save with raw Lua IO.
1 Like

If you’re making your first game, it might be a good idea to start small! Think about the main game mechanic and prototype that. Starting with multiple worlds and config files when making games is usually tricky, because so much of your game is not yet known.

3 Likes
  1. even its a small file? i find 1 file more convenient to work with
  2. “Premature optimization is the root of all evil” im aware of this but it’s really hard for me to not do it, i suffer from being a perfectionist, really bad i know.

i only have 2 phones, both pretty powerful, so in my case testing things always end up top notch.
thats why i ask, dont know how weaker phones are performing.

thanks for help

  1. Personal preference, I find these kinds of data better to be in their own place, but you can do what you like best.
  2. The main concern is just that sys.save / load has hard limits on size. If you know you are going to want large file sizes then using raw IO would be best to do.

You will very likely have a very hard time making a game that runs slow or has other issues unless you do very expensive calculations every frame or use massive textures. You can check the memory usage of your game too and if it’s under 100MB you are fine on the majority of mobile devices out there.

1 Like

If it’s only a couple of values per level then I’d probably keep it all in a single file, but if it’s more data, like the level design/structure then it’s probably better to have one level per file.

This is solid advice. Focus on this and not too much on the perfect way to structure your data until you know more about the game you are creating.

2 Likes

My suggestion is the same as source code.
Start with one and depending on the growth, then split it as necessary.

2 Likes

ok, thanks guys

@britzl it’s only for keeping track of player progress, no structure data at all, for that i have my level manager module and data files.

I have no problems working with config files and bigger projects in general, it’s really only the mobile part im not confident with.
My project is not in the beginning state as some of you might think, im far beyond that :slight_smile: I already work with worlds and levels etc, all going good.
But here and there i go through my code and try to optimize and thats why i sometimes ask simple questions like this one :smiley:

2 Likes