Forum rules - please read before posting.

Action to copy save without loading it first?

edited August 2021 in Technical Q&A

I've set up save profiles to look like a single save game. The player can only press "Continue" on the main menu, which then loads the autosave. There is no Load interface nor a way for the player to save manually.

The other save slots are used when the player reaches certain points in the story, and they can only be accessed as "rewind" points. I have a Rewind interface where the player can select one of those points, and when they do so, the autosave and any other more recent rewind points are deleted. Only then will that save be loaded.

What I want to be able to do is to copy the save point the player has selected into the autosave slot without having to load that save first and immediately run the autosave action. Is it possible to do this?

A similar action for profiles would be great as well. Is there a way to make it work? I'd like to allow the player to copy their profile (and all the saves within it) into a different profile, so that they can play around with one without damaging the other.

Comments

  • edited August 2021

    Tricky one.

    Save game data, filenames, and options/profile data are all linked. Copying a save to another slot would need to involve loading the original file, applying changes to its internal IDs, overwriting the new file, and then doing the same to options data. How saves are written to is also dependent on your platform / iSaveFileHandler interface. There's a lot of room for error, and I'm a bit wary of anything that could potentially corrupt a save file.

    Copying profiles would be even more so. Focusing on the first issue for now: would it be possible to rely on a different approach, as opposed to overwriting save-games?

    If you set a Global Variable's Link to field to Options Data, then that variable's value is synced with the active Profile - not any specific save point. Perhaps this could be used to store an Integer that represents which save index (or ID) to continue from, as opposed to relying on the Autosave for this?

    The Save: Save or load Action has the ability to load a specific save index/slot, and this can be set by a parameter. If you define an Integer parameter in your ActionList, you can precede this Action with an ActionList: Set parameter Action to set this parameter to the value of your Options-linked Variable, so that it loads this save instead.

  • Thanks, Chris, I think I've sorted the first issue. I used to have two main menus, one that said "New Game" and another that said "Continue", and the presence of an autosave was what defined which one would be shown. I changed this to check if there are any saves at all, in which case "Continue" is displayed.

    Now the "Continue" actionlist is set to "Continue from last save" rather than loading the autosave. Just to be sure: how does AC identify the last save? I'm assuming it's by the file's timestamp?

    Also, I have one more issue I need to fix. I need to extract a string variable from the save file (which holds the in-game time for that save), and then copy this to a variable linked to options data. I've tried something like this:

            int saveNumber = AC.GlobalVariables.GetIntegerValue(15);
            SaveFile saveFile = KickStarter.saveSystem.GetSaveFile(saveNumber);
            List<GVar> saveVars = SaveSystem.ExtractSaveFileVariables(saveFile);
    
            string saveTime = saveVars[5].GetValue();
            AC.GlobalVariables.SetStringValue(10, saveTime);
    

    This actually works! BUT the GVar list extracted from the save file seems to keep the variables by the order we set them on the AC Manager, not by the actual variable number. Is there a way to get the variable by the number instead?

  • Just to be sure: how does AC identify the last save? I'm assuming it's by the file's timestamp?

    For it to work across all file handlers (e.g. PlayerPrefs as well), the last-recorded save is stored in the Profile/Options data. You can see this listed as the "Last save ID" under the selected Profile in the Save File Manager.

    the GVar list extracted from the save file seems to keep the variables by the order we set them on the AC Manager, not by the actual variable number. Is there a way to get the variable by the number instead?

    Variables should always be accessed by their ID or label, not their index from an array/list. If "5" represents the ID of the variable you want to read, replace:

    string saveTime = saveVars[5].GetValue();
    

    with:

    GVar correctVar = null;
    foreach (GVar saveVar in saveVars)
    {
        if (saveVar.id == 5)
        {
            correctVar = saveVar;
            break;
        }
    }
    string saveTime = correctVar.GetValue();
    
  • edited August 2021

    Thanks! I got it to work properly now.

    I don't know if this is intended, but "Continue from last save" doesn't appear to work when the last save has been deleted. The second to last save doesn't seem to inherit "last save" status when the last one is gone. But I only tried deleting it from the Save-game Manager, not from an actual actionlist, so maybe that's why.

    This isn't a problem for me because I'm only using 9 saves in order throughout the game, so it's easy to check all slots and load the highest one available, but I thought I'd let you know in case it's a problem in other circumstances.

  • Thanks - yes, it's a limitation I'm aware of. When deleting a save in-game, the "last save ID" will be reset - it can't currently know which was the second-to-last. This value will not be changed at all, however, if the save is deleted via the Save-game Manager.

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.