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 ,. Escape chars are not supported.

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/


A list of notable projects that use this system: