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.
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!
Using Dialogue System for Settings values
-
- Posts: 7
- Joined: Sat Jul 09, 2022 10:35 pm
Re: Using Dialogue System for Settings values
Hi,
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:
You could use PlayerPrefs to save and load it like this:
You could also write some C# methods to get those values:
Then you can register those methods with Lua: (tutorial, manual)
Then you can use those methods in the Dialogue System, such as:
No. (Or at least not easily.)radioactivedogs wrote: ↑Sat Jul 16, 2022 11:26 am- Could I exclude a variable group from being 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();
Code: Select all
PlayerPrefs.SetString("Settings", JsonUtility.ToJson(settings));
...
settings = JsonUtility.FromJson<Settings>(PlayerPrefs.GetString("Settings"));
if (settings == null) settings = new Settings();
Code: Select all
public bool IsDemo { return settings.Demo; }
public bool IsUsingController { return settings.UsingController; }
public bool ShouldSkipDialogue { return settings.SkipDialogue; }
//etc.
Code: Select all
void Awake()
{
Lua.RegisterFunction("IsDemo", this, SymbolExtensions.GetMethodInfo(() => IsDemo()));
//etc.
}
- Dialogue Text: "I see you're playing the demo. I hope you like the game so far!"
- Conditions: IsDemo() == true
-
- Posts: 7
- Joined: Sat Jul 09, 2022 10:35 pm
Re: Using Dialogue System for Settings values
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.
Re: Using Dialogue System for Settings values
The Lua implementation is native C#, so it has decent performance. But it's not the right tool for this particular job.