Getting around save limits

Edit: This thread was created based on old information, but could still help a few people who need to create large save files.

Original post:

As we all know, saving is limited to a table with around 194 entries. I would like to 200 levels, with each level saved as an entry in a table (indicating if a level is unavailable, available, completed, or completed with a gold star). i.e. if self.savefile[32] = 0, then level 32 level is unavailable. I’d also like to store various other user settings.

What advice would you give to get as much information as possible into the save file?

That’s news to me! I didn’t have a reason to look into this yet, but I will eventually need to save way more data than that.

At a glance it seems to me you could simply split the save file into two. Other than that, using io functions looks like the way to go.

I’ll definitely watch this thread. Might learn something useful.

Clarification, sys.save() currently stores exactly 512kb. Your entries are quite large (1kb+!) if you only fit 194 of them.

Also, to better answer your question, you need to provide info about what you actually want to store.
But sure, some general notes:

  • Don’t store things you can recalculate. E.g. store a seed value for the RNG
  • Don’t store strings. Strings are large!
  • Store bitpacked values where applicable. Numbers in Lua are 64 bits. Although, be aware that we actually only store the single floating point value (32 bits). I’d say this combination is a very advanced route to take, so be aware.

For the interested, here’s a good video about some tricks:

EDIT:

  • You also have the zlib module which lets you compress/decompress a data blob. You could encode your data into a string, and compress that, then store that.
    But I don’t think it would help in this case, where you probably want a good balance between eas-ofuse and readability.

  • For 2d coordinates you only need to use 2 coordinates, whereas a vector3 stores 3.

  • If your coordinates are in a grid, you can store the grid dimensions, and instead store a grid index (y*grid_width+x), in one number.

  • If you have a sparse grid, only store the non empty cells

7 Likes

And if you still need to store more data than 512kb you can use the standard io.* functions.

Oops!

Thanks for your replies! It appears that the save file limitations have changed since the last time I was looking into this. My entries are single digit numbers. Each level has an entry in a table, and each one is 0, 1, 2, 3, 4, 5. I am not sure why my save file was coming out like it was.

Matthias, those are some useful tips. I’ll have a look at that video, it seems interesting.

2 Likes