Using Dialogue System for Settings values

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
radioactivedogs
Posts: 7
Joined: Sat Jul 09, 2022 10:35 pm

Using Dialogue System for Settings values

Post by radioactivedogs »

Hi Tony,

One thing I'm trying to figure out in the transition to Dialogue System is how we should handle our settings values. It would be ideal to be able to access these values via Lua, Below I've attached a photo of part of our configuration file for our game, one of the big features is the ability to have variables that are created at launch but never saved, useful for stuff like checking platform, if the build is a demo, controller type, etc.

Image

My big questions are the following.
- Could I exclude a variable group from being saved?
- Are variables created at runtime saved?

I assume I'll need to write some of my own code to make sure it (the settings file) is serialized and saved to disk as its own file, so the values aren't saved in each slot when using the SaveSlot method but wanted to make sure I'm not missing something you already implemented!
User avatar
Tony Li
Posts: 22145
Joined: Thu Jul 18, 2013 1:27 pm

Re: Using Dialogue System for Settings values

Post by Tony Li »

Hi,
radioactivedogs wrote: Sat Jul 16, 2022 11:26 am- Could I exclude a variable group from being saved?
No. (Or at least not easily.)
radioactivedogs wrote: Sat Jul 16, 2022 11:26 am- Are variables created at runtime saved?
Yes. The entire table of runtime variables (including variables defined in the dialogue database) are dumped into the save data. This save data is then saved into a slot, so it's slot-specific.

I don't think Lua variables are the best place for your settings values. However, you can still make those settings values available to Lua so you can check them in Dialogue System Triggers' Conditions, in conversations, etc.

For example, say you keep those values in a C# class:

Code: Select all

[System.Serializable]
public class Settings
{
    public string Platform = "";
    public bool Demo = false;
    public bool UsingController = false;
    public bool SkipDialogue = false;
    //etc.
}

public Settings settings = new Settings();
You could use PlayerPrefs to save and load it like this:

Code: Select all

PlayerPrefs.SetString("Settings", JsonUtility.ToJson(settings));
...
settings = JsonUtility.FromJson<Settings>(PlayerPrefs.GetString("Settings"));
if (settings == null) settings = new Settings();
You could also write some C# methods to get those values:

Code: Select all

public bool IsDemo { return settings.Demo; }
public bool IsUsingController { return settings.UsingController; }
public bool ShouldSkipDialogue { return settings.SkipDialogue; }
//etc.
Then you can register those methods with Lua: (tutorial, manual)

Code: Select all

void Awake()
{
    Lua.RegisterFunction("IsDemo", this, SymbolExtensions.GetMethodInfo(() => IsDemo()));
    //etc.
}
Then you can use those methods in the Dialogue System, such as:
  • Dialogue Text: "I see you're playing the demo. I hope you like the game so far!"
  • Conditions: IsDemo() == true
radioactivedogs
Posts: 7
Joined: Sat Jul 09, 2022 10:35 pm

Re: Using Dialogue System for Settings values

Post by radioactivedogs »

As always very helpful thank you so much! I did actually try using Lua and it was a mess trying to get what I wanted and was probably unperformant as hell.
User avatar
Tony Li
Posts: 22145
Joined: Thu Jul 18, 2013 1:27 pm

Re: Using Dialogue System for Settings values

Post by Tony Li »

The Lua implementation is native C#, so it has decent performance. But it's not the right tool for this particular job.
Post Reply