Saving issue

Announcements, support questions, and discussion for the Dialogue System.
User avatar
Tony Li
Posts: 21981
Joined: Thu Jul 18, 2013 1:27 pm

Re: Saving issue

Post by Tony Li »

Hi,

Yes. Let's say you're keeping track of the most recently-saved slot number in a variable named mostRecentSlotNumber, and your character customization is in a Saver script named CharacterCustomizationSaver saved under the key "customization". To load save data without applying it.

Code: Select all

using PixelCrushers;
...
SavedGameData savedGameData = SaveSystem.storer.RetrieveSavedGameData(mostRecentSlotNumber);
string s = savedGameData.GetData("customization");
CharacterCustomizationData characterCustomizationData = SaveSystem.Deserialize<CharacterCustomizationData>(s);
SealDev
Posts: 85
Joined: Thu Jun 24, 2021 5:45 am

Re: Saving issue

Post by SealDev »

Awesome! How about retriving just a variable value from that slot?
User avatar
Tony Li
Posts: 21981
Joined: Thu Jul 18, 2013 1:27 pm

Re: Saving issue

Post by Tony Li »

If you're talking about a variable in your CharacterCustomizationData, like this:

Code: Select all

...
CharacterCustomizationData characterCustomizationData = SaveSystem.Deserialize<CharacterCustomizationData>(s);
string weaponName = characterCustomizationData.weaponName;
If you're talking about a Dialogue System variable, since you're in the main menu you can just apply it to the Dialogue System since the data will be reset when you actually load a saved game. Example:

Code: Select all

using PixelCrushers.DialogueSystem;
...
string s = savedGameData.GetData("ds"); // Assumes your DialogueSystemSaver's Key is "ds".
PersistentDataManager.ApplySaveData(s);
string myVariableValue = DialogueLua.GetVariable("My Variable");
SealDev
Posts: 85
Joined: Thu Jun 24, 2021 5:45 am

Re: Saving issue

Post by SealDev »

I tried for a couple of hours but couldn't get it to retrieve data!

It debugs 0, the default variable value of "CurrentHat" not just OnSaveDataApplied, but also on update.

My game only uses save slot 0. Don't know why but data is not applying. I also made sure to give the DialogueSystemSaver the key "ds", still won't load.
Attachments
1.png
1.png (32.68 KiB) Viewed 641 times
User avatar
Tony Li
Posts: 21981
Joined: Thu Jul 18, 2013 1:27 pm

Re: Saving issue

Post by Tony Li »

Hi,

Try breaking it down to make sure we're getting the correct data from the saved game

Code: Select all

string s = SaveSystem.storer.RetrieveSavedGameData(0).GetData("ds");
Debug.Log("Saved DS data: " + s);
PersistentDataManager.ApplySaveData(s);
...
SealDev
Posts: 85
Joined: Thu Jun 24, 2021 5:45 am

Re: Saving issue

Post by SealDev »

Using exactly your code, it outputs nothing (1.png)

And yes, I do already have a save file, with a different hat equipped (2.png). It's just that it only loads on Play

Pic of dialogue manager object (3.png / 3b.png)
Attachments
3b.png
3b.png (10.88 KiB) Viewed 630 times
3.png
3.png (51.86 KiB) Viewed 633 times
2.png
2.png (3.27 KiB) Viewed 633 times
1.png
1.png (4.27 KiB) Viewed 635 times
User avatar
Tony Li
Posts: 21981
Joined: Thu Jul 18, 2013 1:27 pm

Re: Saving issue

Post by Tony Li »

The key is different since you've ticked the DialogueSystemSaver's Append Saver Type To Key. Options:

1. UNtick Append Saver Type To Key. Re-save the game so the data is saved under "ds".

2. Or use "ds_DialogueSystemSaver" for the key.
SealDev
Posts: 85
Joined: Thu Jun 24, 2021 5:45 am

Re: Saving issue

Post by SealDev »

Thank you so much :)

Final question! In general, when running string operations, is performance worse with longer words than shorter ones?
User avatar
Tony Li
Posts: 21981
Joined: Thu Jul 18, 2013 1:27 pm

Re: Saving issue

Post by Tony Li »

In general, the performance difference in length in negligible.

You do you want to avoid manipulating strings -- such as concatenating them like this:

Code: Select all

string s = "One" + "Two";
because it generates garbage memory that will need to be garbage-collected at some point. If you're doing it every once in a while, it's fine. Just don't do it every frame, such as in Update().
Post Reply