Resetting variables to a different initial state than the one they originally had in a save file

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
LostTrainDude
Posts: 74
Joined: Wed Mar 21, 2018 2:14 pm

Resetting variables to a different initial state than the one they originally had in a save file

Post by LostTrainDude »

[Unity 2021.3.42f1 - Articy v2 - AC v1.81.6 - DS v2.2.46.1]

Hi Tony,

To cater for the lack of string support in Articy v2 variables, I have been using ints with verbose names to track the quest progress in the game I'm working on.

As an example imagine a quest, "Open The Door", where the steps are to first find the key then open the door and leave.
I would lay it out in Articy like so:

q_OpenTheDoor.progress = -1 (this meaning the quest still has to start)
q_OpenTheDoor.START = 0
q_OpenTheDoor.GOT_KEY = 1
q_OpenTheDoor.LEFT_ROOM = 2

Then, when in DS I want to start specific conversations \ lines for specific quest states, I would write my conditions in Articy like so:

q_OpenTheDoor.progress == q_OpenTheDoor.GOT_KEY ---> "Nice! I wonder if this is the key to the door"
q_OpenTheDoor.progress == q_OpenTheDoor.LEFT_ROOM ---> "Ah, fresh air!"

and if the progress is different from any of the above ---> "I have to get out of here"

Now imagine the following procedure:
- I start this quest, progress correctly advances to the same value as q_OpenTheDoor.START
- I get the key, progress correctly advances to the same value as q_OpenTheDoor.GOT_KEY
- I save and exit. q_OpenTheDoor.progress value is correctly set to the same value as q_OpenTheDoor.GOT_KEY
- I get back in Articy and swap the values of q_OpenTheDoor.GOT_KEY and q_OpenTheDoor.LEFT_ROOM
- I write a small script that updates q_OpenTheDoor.GOT_KEY and q_OpenTheDoor.LEFT_ROOM to their *new* initial value, after restoring a previous save file:

Code: Select all

string initialValue = DialogueManager.MasterDatabase.GetVariable("q_OpenTheDoor.GOT_KEY").InitialValue;
int currentValue = DialogueLua.GetVariable("q_OpenTheDoor.GOT_KEY").asInt;

DialogueLua.SetVariable("q_OpenTheDoor.GOT_KEY", initialValue);

initialValue = DialogueManager.MasterDatabase.GetVariable("q_OpenTheDoor.LEFT_ROOM").InitialValue;
currentValue = DialogueLua.GetVariable("q_OpenTheDoor.LEFT_ROOM").asInt;

DialogueLua.SetVariable("q_OpenTheDoor.LEFT_ROOM", initialValue);
- Reimport the Articy project into the game

When I run the game again I find out that everything is correct:
- q_OpenTheDoor.GOT_KEY is now set to 2
- q_OpenTheDoor.LEFT_ROOM is now set to 1
- q_OpenTheDoor.progress is still set to 1

But, when I play the conversation that checks for the q_OpenTheDoor.progress value I get the "I have to get out of here" response, even if the variables are correctly showing the correct values.

My question is, am I doing something wrong?

I hope I made everything clear! I'm considering this as a way to patch our game after launch if needed, and without breaking save games for our players.

Thanks a lot as always!
User avatar
Tony Li
Posts: 22085
Joined: Thu Jul 18, 2013 1:27 pm

Re: Resetting variables to a different initial state than the one they originally had in a save file

Post by Tony Li »

Hi,

Double check that the variables are actually getting set to the values you expect. You can use a Lua Console in-game or use the Dialogue Editor window's Watches tab if you're playing in the Unity editor's play mode.

Temporarily set the Dialogue Manager's Other Settings > Debug Level to Info. When the conversation checks the conditions, it will report if the conditions are true or false so you can trace through its logic.

Also, set the Save System component's version field. The Save System will store the current value of the version field in saved games. When you load a saved game, you can check SavedGameData.version.
LostTrainDude
Posts: 74
Joined: Wed Mar 21, 2018 2:14 pm

Re: Resetting variables to a different initial state than the one they originally had in a save file

Post by LostTrainDude »

Do you have any pointers on how to correctly set the SaveSystem.version upon saving? Before posting I tried to subscribe the patch to the SaveSystem.loadEnded event, but it didn't run the code. Now I am subscribing the patch to the AC.EventManager.OnFinishLoading event.

In the meantime, here's a sequence of screenshots from Articy, the Variable and Watches tabs and the Console (incl. DS debug info).
User avatar
Tony Li
Posts: 22085
Joined: Thu Jul 18, 2013 1:27 pm

Re: Resetting variables to a different initial state than the one they originally had in a save file

Post by Tony Li »

Hi,

Hook into SaveSystem.saveDataApplied. This C# event occurs after the save data has been applied to the Dialogue System (via DialogueSystemSaver component) and other savers.

In your event handler, you can check SaveSystem.currentSavedGameData.version.
LostTrainDude
Posts: 74
Joined: Wed Mar 21, 2018 2:14 pm

Re: Resetting variables to a different initial state than the one they originally had in a save file

Post by LostTrainDude »

I apologize, but I'm not really sure I understand the usage of SaveSystem, or at least I don't know how it should be working for my current situation.

What I mean by this is that I don't remember ever using any DialogueSystemDataSaver on any of my GameObjects in the game, as I handle all of my save data through AdventureCreator. Unless there are DialogueSystemDataSavers working in the background somewhere, that is.

Did you mean I should attach one to the Dialogue Manager prefab? Would it be for the sole purpose of making this kind of patches possible?

Also, I just realized: if I patch those same variable values via Lua.Run() instead of DialogueLua.SetVariable() it seems to be working just fine, to the extent that I might end up just doing that!
User avatar
Tony Li
Posts: 22085
Joined: Thu Jul 18, 2013 1:27 pm

Re: Resetting variables to a different initial state than the one they originally had in a save file

Post by Tony Li »

Oh, sorry, I forgot you were using Adventure Creator. Adventure Creator handles the saves, so disregard SaveSystem.version. Lua.Run should be fine!
LostTrainDude
Posts: 74
Joined: Wed Mar 21, 2018 2:14 pm

Re: Resetting variables to a different initial state than the one they originally had in a save file

Post by LostTrainDude »

Thank you! I'll just do that then :)
Post Reply