My Save Code Format


Over many years of developing Scratch projects, I have settled on a simple-to-use and easy-to-understand save code format and now use it on pretty much everything. I call it CSKV, which stands roughly for comma-separated key/values (I have not settled on a specific name). The only reserved chars are colon : and comma ,. I usually don't need escape characters so my implementation does not use them but it's quite simple to modify to account for.

Example (with colour showing the key and values):

user:awesome-llama,id:8832510,scratchteam:false

But what happens if you need to store more than a single value? There is support for lists stored alongside each key. Implementation depends on the project but the general setup is to have the first number after a key representing the length of the list:

recent_projects:3,The Mast,Submersible,Road Network Designer

The code responsible for reading the save code will be designed to understand what data is expected for a given key. For example, recent_projects will be expected to be a list, the length determined by the first item. user will be expected to always be a single value.

I often also include a magic number at the start of the save code, like this:

account_info,user:awesome-llama,id:8832510,scratchteam:false

This just helps to ensure the data comes from the right place as well as ensure I know what a save code stores.

Also, with save codes that are intended to be used by others and not just some internally-used thing, I also ensure a project version number and an approximate date is provided as keys. Username may also be useful too. The following example is from my game Submersible but trimmed down to just the first bit with the version (v for project version, sv for save code version) and time (t, seconds since 2000):

SUB,v:1.0,sv:1,t:731066503,[...]


Here is a Scratch project with the scripts I typically would use to implement the above: https://scratch.mit.edu/projects/114633511/


If using this for a save code that saves game progress, it is apparent that the simplicity and readability also means it is easy to cheat. In my opinion, this doesn't matter as the "see inside" button exists on all Scratch projects and provides even more opportunities to cheat. I suggest if you want to stop the simplest, most opportunistic cheating, you include a checksum for the important values (e.g. currency, high score).


A list of notable projects that use this system: