Forum rules - please read before posting.

Any way to continue from last save file without Options Data?

Hello everyone. I'm using AC v 1.74.2

I have a "continue“ button in my main menu. I'm using the "continue from last save" node. It works great when I'm on a single computer. However, I noticed that it uses OptionsData to determine the last save from the ID.

    public static bool ContinueGame ()
    {
        if (Options.optionsData != null && Options.optionsData.lastSaveID >= 0)
        {
            return LoadGame (Options.optionsData.lastSaveID);
        }
        return false;
    }

This causes problems when trying to continue on another device with synced save files. The options data is saved to player prefs, and thus, not carried over to the new device. So on the new device, the lastSaveID might be different or not exist at all. So is there some setting or something I could do to safely retrieve the last save? Or a way to edit the script to do so?

Comments

  • You can switch your Options file handled to OptionsFileHandler_SystemFile to have Options data be placed in files in the same way as save-games:

    SaveSystem.OptionsFileFormatHandler = new OptionsFileHandler_SystemFile ();
    

    Otherwise, a custom script could read the save files themselves and work out which has the latest modified timestamp.

    A function along these lines should return the ID of the latest save this way:

    int GetLatestSaveID()
    {
        string saveDirectory = SaveSystem.PersistentDataPath;
        string filePrefix = KickStarter.settingsManager.SavePrefix;
    
        int largestWriteTime = 0;
        int largestWriteTimeID = 0;
    
        DirectoryInfo dir = new DirectoryInfo(saveDirectory);
        for (int i = 0; i < KickStarter.settingsManager.maxSaves; i++)
        {
            int saveID = 0;
    
            string filename = filePrefix + SaveSystem.GenerateSaveSuffix(saveID);
            string filenameWithExtention = filename + SaveSystem.GetSaveExtension();
    
            var info = dir.GetFiles(filenameWithExtention);
            if (info == null) continue;
    
            foreach (FileInfo fileInfo in info)
            {
                if (fileInfo.Name != filenameWithExtention) continue;
    
                var origin = new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc);
                TimeSpan diff = fileInfo.LastWriteTime.ToUniversalTime() - origin;
                var writeTime = (int)diff.TotalSeconds;
    
                if (writeTime > largestWriteTime)
                {
                    largestWriteTime = writeTime;
                    largestWriteTimeID = saveID;
                }
            }
        }
    
        return largestWriteTimeID;
    }
    
  • Oh great! So I could just add this to a script in my main menu and set Options.optionsData.lastSaveId to this?

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.