Forum rules - please read before posting.

[Best Practices] Keeping savegame integrity among game updates. Savegame version checking with AC

edited November 2019 in Technical Q&A

Hi there!

I'm developing a game with frequent updates and, I'm stumbling on various issues I'd have to solve, someway:

1) I'm adding new scenes to the game, so I have to keep the scene indexes and scene build order fixed, since the savegames depend on the build index.
2) I should be able to check if the save version is compatible with the current version, and determine which version each save has been created with, before loading it.
3) I'd have to handle corner case scenarios when a new element in the save is missing/is new to the current version.

How would you handle these points?

It may be a bit general and not really AC related, but I'd love to know how much of AC I can use to handle the above issues :)

I've already read the manual about saving games and importing saves from a different game.

Thanks in advance.

Comments

  • I'm adding new scenes to the game, so I have to keep the scene indexes and scene build order fixed, since the savegames depend on the build index.

    Correct.

    I should be able to check if the save version is compatible with the current version, and determine which version each save has been created with, before loading it.

    If you stored your "game version" inside a Global Variable, then you could access it through script. This'd currently be tricky, since you'd have to manually load/deserialize the save file, but I shall look into updating the iSaveFileHandler's Load function to return the actual save data, so that it can be extracted for this purpose.

    I'd have to handle corner case scenarios when a new element in the save is missing/is new to the current version.

    Scene data values (i.e. Remember scripts) are replaced outright upon loading a save file, or cleared if none is found. The latter is so that a scene reverts to its default state if you're loading a save file that doesn't have data for a room you visited beforehand. Typically this will be what you want, but it's also possible to implement a new FileFormatHandler to also incorporate current level data instead.

    This is handled in the DeserializeAllRoomData function. An example modification to FileFormatHandler_Binary may be:

    public List<SingleLevelData> DeserializeAllRoomData (string dataString)
    {
        List<SingleLevelData> loadedLevelData = (List<SingleLevelData>) DeserializeObject <List<SingleLevelData>> (dataString);
    
        foreach (SingleLevelData singleExistingLevelData in KickStarter.levelStorage.allLevelData)
        {
            bool foundMatch = false;
            foreach (SingleLevelData singleLoadedLevelData in loadedLevelData)
            {
                if (singleLoadedLevelData.sceneNumber == singleExistingLevelData.sceneNumber)
                {
                    foundMatch = true;
                }
            }
    
            if (!foundMatch)
            {
                loadedLevelData.Add (singleExistingLevelData);
            }
        }
    
        return loadedLevelData;
    }
    
  • edited November 2019

    Thanks Chris!

    is that the same function I should take as reference when extracting a global variable from a savegame?

    Would it be possible to have an AC global settings option to save/load... savegames by scene name and not by build index (the build index could still be retrieved using the APIs, or the loaded scene loaded by using SceneManager.LoadScene(string sceneName) instead of (int buildIndex) )?

    Having and maintaining a fixed build order is less...flexible than saving by name (both require some extra attention).
    Also because, if the scene is missing, or is the wrong one for some reason, you can't tell by the index, but you could even "override" renamed scenes from a savegame.
    I'm not a fan of referring things by name/string (that's why I was suggesting some sort of intermediate level hashset maintained by AC), but I believe this could be an exception.

    I'm definitely looking forward the next update! :)

  • is that the same function I should take as reference when extracting a global variable from a savegame?

    The above code snippet? No. With v1.70, I'll provide functions to load and extract "global" data from a save file. This could then be used to extract variable values.

    Would it be possible to have an AC global settings option to save/load... savegames by scene name and not by build index

    It's something to consider, but as scene name is not currently recorded bear in mind that existing saves would not be valid when switched over to use names.

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Welcome to the official forum for Adventure Creator.