Crave For Games

The text below is one of the notes from the StoneDrop development log. If you want a list of only technical articles you can go to the Articles page.

Game autosave and autoloading was implemented. Right now the last unfinished level always automatically loaded and there is no opportunity to restart the level but it will be changed when the UI is be ready (UPD June 2016: autosave and autoload disabled, UI is ready :) )


While I was implemented the autosave/autoload feature I've came up with an interesting case to be aware of. Because later it's supposed that the user will be able to create custom levels the case is the following:

- create a level

- start to play the level

- leave it (the progress will be autosaved)

- change the level in the level editor

- try to load the autosave

- obviously the autosave data is garbage now because the level is not the same now as it was while saving.


To address such problem I introduced a hash function which generates unique integer value depending on the content of the level. Then a 7-digit string being generated from this integer hash by an algorithm[1] which uses 0-9 and a-z symbols as a 36-based numeral system. The string is used as a file name for the autosave (that's why capital letters are not used as the case-sensitivity may cause problems on some platforms). Now any change in the level's content will result in different file name to search the game save data in and thus eliminates the errors of incorrect saving data.


The other problem I've encountered was related to WebGL build. It turns out that no decomissioning-related methods (OnDisable, OnDestroy, OnApplicationQuit, etc.) are being called when the user closes the browser tab with a game. So apart from other target platforms the WebGL build saves the game after each turn.

After addressing all previous challenges I've faced the fact that all browsers don't save any data being written to Application.persistentDataPath after the tab with a game was closed. But I'll describe the workaround for this in the next post.


Link 1:

This article in social networks: