How should I go about using the Save System for Visual Novel Values?

Announcements, support questions, and discussion for the Dialogue System.
2linescrossed
Posts: 47
Joined: Tue May 16, 2023 10:37 pm

How should I go about using the Save System for Visual Novel Values?

Post by 2linescrossed »

Heya! I've been looking into the documentation for the save system, but I've been wondering how I should go about adding in additional values for the sake of saving? Apologies for my inexperience, as I've never made my own save systems before, so I'm trying to get my bearings on it.

Specifically, there are a lot of integer values I want to account for, as well as flags. While I can assume the save system is already very compatible with the dialog database's variables, I probably shouldn't be keeping most of my ints inside of the Dialogue Database.

I have to keep track of quite a few values, as there are eleven main characters in the game (so far), each of whom can interact with the player as well as each other. So there's values/number flags that check how many conversations have been progressed through per character, as well as relationship values with the player.

Anyway, I'll keep it brief for now - but what's the best way of handling this? Do I just make a separate script that has 'the master data', and sync it with whatever is saving the dialogue database's systems?
User avatar
Tony Li
Posts: 22107
Joined: Thu Jul 18, 2013 1:27 pm

Re: How should I go about using the Save System for Visual Novel Values?

Post by Tony Li »

Hi,

There are two ways to do this:

1. The simplest from a code perspective is to use Dialogue System variables in your dialogue database. They automatically get saved in your saved games, and you can see their values at runtime in the Dialogue Editor's Watches tab. Tip: Use "." in your variable names to group them into submenus in dropdowns.

2. Or write a custom saver. A custom saver can save other data, such as variables in your own C# scripts.
2linescrossed
Posts: 47
Joined: Tue May 16, 2023 10:37 pm

Re: How should I go about using the Save System for Visual Novel Values?

Post by 2linescrossed »

Hey, currently trying to make use of the custom savers, but I've realized there's a lot I still don't know how to work with in the json/playerprefs over here.
Particularly, how do I get the system to display some of the stats in the base file, for example? Let's say I wanted to have the save slots, and I wanted to display the player's name, time played, etc, how would I get the data from the specific save slots (rather than just loading the entire thing), and update the button accordingly? Does this have to be a DialogueSystem variable, or can it work for Custom saver variables as well?

Also, what's a good way for listening to when the game saves, so that I can tell the UI to update itself accordingly?
User avatar
Tony Li
Posts: 22107
Joined: Thu Jul 18, 2013 1:27 pm

Re: How should I go about using the Save System for Visual Novel Values?

Post by Tony Li »

Hi,

This gets a bit into the scripting weeds, but to know when the game has been saved you can hook into the C# event SaveSystem.saveEnded. And to show summary info in your saved game list, see: How To: Include Summary Info In Saved Games
2linescrossed
Posts: 47
Joined: Tue May 16, 2023 10:37 pm

Re: How should I go about using the Save System for Visual Novel Values?

Post by 2linescrossed »

Hmm, okay, I'm having issues with this, where despite me clearly calling the Summary, and having the right key for it, I always get null reference exceptions.

Code: Select all

    void FileDisplay()
    {
        //Calling this refreshes the buttons, ideally.
        if (SaveSystem.HasSavedGameInSlot(slotNo))
        {
            var s = savedGameData.GetData("GameSummary");
            
            var summary = SaveSystem.Deserialize<SaveFileDisplaySaver.Data>(s);
            Debug.Log(summary.playerName.ToString());

           // playerName.text = FormattedText.ParseCode("[var=PCName]");
           // tokens.text = FormattedText.ParseCode("[var=PlayerTokens]");
        }
        else
        {
            playerName.text = "No Save File in Slot";
        }
    }
I was originally trying to use the variable names that way until I realized that meant the save slots couldn't differentiate between specific files. The slots clearly save correctly, but I get an error on trying to get the data at all, in the 'var s = savedGameData.GetData', even with the right key.
It definitely has different keys to the other savers on the DialogueManager, and it IS on the manager.
User avatar
Tony Li
Posts: 22107
Joined: Thu Jul 18, 2013 1:27 pm

Re: How should I go about using the Save System for Visual Novel Values?

Post by Tony Li »

Hi,

Before calling this line of code:

Code: Select all

var s = savedGameData.GetData("GameSummary");
are you setting savedGameData to something?

Typically you'll use SaveSystem.storer.RetrieveSavedGameData(), such as:

Code: Select all

if (SaveSystem.HasSavedGameInSlot(slotNo))
{
    var savedGameData = SaveSystem.RetrieveSavedGameData(slotNo);
    if (savedGameData != null)
    {
         var s = savedGameData.GetData("GameSummary");
         ....
2linescrossed
Posts: 47
Joined: Tue May 16, 2023 10:37 pm

Re: How should I go about using the Save System for Visual Novel Values?

Post by 2linescrossed »

Hmm, so I was initially doing it JUST in the Start, which was why the script broke? I'm not sure that checks out but it works slightly better now, which is what's important.

Now I've found a new baffling issue - currently, saving in one file saves over EVERY existing file at the same time, but ONLY existing files, not empty slots. I've got six buttons, 3 for loading, 3 for saving. They're matched with the right respective numbers - ie, Save Slot 1 is Savesystem.SaveGameToSlot, Load Slot 1 is SaveSystem.LoadGame - both of them have '1' as their numbers, going 1-3. (Slot 0 would be for the autosave later). I'm confused as to why it may be saving over only existing files, since it can clearly distinguish empty slot files. I also checked the files to make sure it wasn't a UI bug, but yeah, it was actively saving OVER all the existing files simultaneously.
What should I do to resolve this?
User avatar
Tony Li
Posts: 22107
Joined: Thu Jul 18, 2013 1:27 pm

Re: How should I go about using the Save System for Visual Novel Values?

Post by Tony Li »

Are you sure it's overwriting each one? If you're only calling SaveSystem.RetrieveSavedGameData(slotNo) in Start, then it will only read the info from one slot.

If you're using the PlayerPrefsSavedGameDataStorer, you can inspect the component and click on the Show buttons to see the contents of each saved game slot.

If you're using the DiskSavedGameDataStorer, you can look in the persistentDataPath for your game (or wherever you've configured DiskSavedGameDataStorer to save) and check the save files.
2linescrossed
Posts: 47
Joined: Tue May 16, 2023 10:37 pm

Re: How should I go about using the Save System for Visual Novel Values?

Post by 2linescrossed »

Ah, I see where I went wrong, I was using the current save file's values for the text, so I stumbled into my own observation from earlier. My bad, but I don't know how I can get the variable from the summary file to actually display properly, it always gives me that 'Lua Result' mumbojumbo on a ToString, and I can't pass it to FormattedText like the DS Variables. What's the way to extract the real text/ints from the summary file without getting the lua text scramble thing?
User avatar
Tony Li
Posts: 22107
Joined: Thu Jul 18, 2013 1:27 pm

Re: How should I go about using the Save System for Visual Novel Values?

Post by Tony Li »

Can you show the code you're using?

I've finished work for the night, but I'll check back in the morning.
Post Reply