Wednesday, 12 November 2014

Saving the Game

I mentioned last week that my big goal before sharing my idle game project was to put in saving. I'm working on it, and encountering three challenges.

First, figuring out a way to sensibly convert the information into a string. Local storage will let me store strings, so that's what I've got to work with. I don't just have a series of numerical values to store. It's not just number of widgets produced, number of each widget producing thing bought, and a bunch of booleans for upgrades acquired, Instead I have names of things that are generated as the game goes on. I don't start knowing how many things I need to store or what kind of information I'll have attached to each thing. I can obviously do whatever I want with strings of course, but this is the kind of fiddly real-life stuff that I hate doing. String manipulation is awful.

Second, I don't want to lock myself out of doing different things in the future. If I add another stat to the game, add new features or add another gear slot or something like that I don't want to have to delete old saves. Usually this is accomplished by adding new things to the end, but I don't have a well defined "end" to add them to.

Third, local storage, as I understand it, is usually stored per domain. Because I'm currently hosting things on google drive, that means I'll be sharing my local storage with everything else on google drive. I don't think this is a really big problem, but it might be a problem in a way I'm not aware of. Maybe it's time I get around to registering or something of that sort.

Anyway, one of the takeaways is that this is going to have the most hackable savegames since Candy Box 2.

And, as there always is, there's a lot of executing, finding out I missed a semi-colon, putting it in, executing again, and being alerted to yet another missing semi-colon. That's a constant. Strangely, though, the last few days have been full of instances of things actually working. I type in a bunch of new stuff in several different places and run it and it works exactly how I wanted it to.

It's like I'm getting better at doing something by practicing.


  1. Build your save state in json, serialize it to a string and save that. Deserialize your string back to json when you load state, and continue to work with objects.

    1. JSON is certainly a good thing to know about. Don't look at the code when I do put the game up, it might burn your eyes.