Need Help With Saving Variables

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
EntertainmentForge
Posts: 23
Joined: Sun Nov 29, 2020 8:50 pm

Need Help With Saving Variables

Post by EntertainmentForge »

Hey Tony,
I can't seem to save the variable. Might be some silly thing, but I made video showing you exactly what I did and maybe you'll notice what I missed.



Thank you!
User avatar
Tony Li
Posts: 22143
Joined: Thu Jul 18, 2013 1:27 pm

Re: Need Help With Saving Variables

Post by Tony Li »

Hi,

The Dialogue Editor's Variables section shows the variables' initial values. To see the variables' current values, use the Watches section or the separate Variable Viewer window.

Then temporarily set the Dialogue Manager's Other Settings > Debug Level to Info. At runtime, when you select "How so?" the Console window should show a line similar to:

Dialogue System: Lua.Run( Variable["necromancerToldYouAboutTheCabbage"] = true )

Make sure you see that line, and also check the current variable value in the Watches section or Variable Viewer window.

When you get to the line "That's how I deal with my...", check the variable again (maybe it changed), and examine the Console window. You should see two lines. The entry whose Conditions are true will report:

Dialogue System: Add Link: "(dialogue text)"

Then other will report:

Dialogue System: Block On False Link: "(dialogue text)"
EntertainmentForge
Posts: 23
Joined: Sun Nov 29, 2020 8:50 pm

Re: Need Help With Saving Variables

Post by EntertainmentForge »

Hey Tony,

Thanks for the help. These debugging tools are super helpful. But I'm still failing to save the variable. It might be because I'm changing the scene as we go from menu to battle.
I explained this in more details in video:

https://youtu.be/Ppt7IblXtHc

Thanks you!
User avatar
Tony Li
Posts: 22143
Joined: Thu Jul 18, 2013 1:27 pm

Re: Need Help With Saving Variables

Post by Tony Li »

Hi,

If you've left the Dialogue Manager's Other Settings > Don't Destroy On Load checkbox ticked (its default value), variable values will survive scene changes. You don't need to save and load them when changing scenes.

When you enter a new scene that has a Dialogue Manager GameObject, the existing Dialogue Manager from the old scene will replace it. However, it's possible that any custom scripts on the new scene's Dialogue Manager will have time to run their Awake() methods before the existing Dialogue Manager replaces it. If you need to do something after a Dialogue Manager has fully initialized, hook into the Dialogue Manager's DialogueSystemController component > initializationComplete C# event. (In general, you usually don't need to do this.)

However, if you've unticked that checkbox and are using a new Dialogue Manager in each scene, hook into the initializationComplete handler, and restore your variables in your event handler. Alternatively, if you've set up the Dialogue System's Save System, just add a Dialogue System Saver component to the Dialogue Manager. This component will take care of it.
Post Reply