Watch Boolean Variables

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
User avatar
ds2497
Posts: 80
Joined: Wed Jun 14, 2023 2:13 am

Watch Boolean Variables

Post by ds2497 »

Hey! Recently, I’ve been working on better managing flags, so I integrated some variables into Dialogue System for Unity. However, when checking values in Watch, I noticed there doesn’t seem to be a Boolean option. Since most of my values are Boolean-based, I was wondering—how can I monitor Boolean values at runtime?

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

Re: Watch Boolean Variables

Post by Tony Li »

Hi,

You should be able to add a watch on a Boolean variable by selecting Menu > Add All Runtime Variables or Add Runtime Variable. Here's an example from DemoScene1:

watchBoolean.png
watchBoolean.png (43.7 KiB) Viewed 2937 times
User avatar
ds2497
Posts: 80
Joined: Wed Jun 14, 2023 2:13 am

Re: Watch Boolean Variables

Post by ds2497 »

Hi, thanks for your response! I can now see Bool values in the editor!

I have two questions:

1.When using LoadFromSlot, when should I assign a new value to a Variable?
Scenario: I want Variable["goblin_killed"] to default to true, but since this variable was newly added, it doesn't exist in older save files. If I understand correctly, loading from a slot will result in nil for this variable. Currently, I’m adding an event to SaveSystem.saveDataApplied and waiting 10 frames before assigning the new value… but I’m not sure if this is the correct approach. Ideally, should there be a VariableLoaded event, and should I modify the value after that?

Code: Select all

private async void Start() {
  SaveSystem.saveDataApplied += PatchSaveData;
}

private void OnDestroy() {
  SaveSystem.saveDataApplied -= PatchSaveData;
}

private async void PatchSaveData() {
  await UniTask.DelayFrame(10, PlayerLoopTiming.Update);
  //Special fix: Convert flag to variable
  foreach(string flag in extractedFlags) {
    DialogueLua.SetVariable(flag, true);
  }
}
2. How can I check if a value is nil in C#?
Right now, I’m using DialogueLua.SetVariable(flag, true) to assign values, but I want to check existing Variables and set any nil values to false. What would be the correct way to do this in C#?

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

Re: Watch Boolean Variables

Post by Tony Li »

Hi,
ds2497 wrote: Mon Mar 03, 2025 12:47 am1.When using LoadFromSlot, when should I assign a new value to a Variable?
Tick the Dialogue Manager's Persistent Data Settings > Initialize New Variables. After loading a saved game, this checkbox will add any variables that you've added after the save and set them to their default values.

Related topic: How To: Handle Saved Game Versions

ds2497 wrote: Mon Mar 03, 2025 12:47 am2. How can I check if a value is nil in C#?
If a variable is nil, DialogueLua.DoesVariableExist("variablename") will be false.

If you use DialogueLua.GetVariable("flag").asBool, this will return true if Variable["flag"] is true, and it will return false if Variable["flag"] is false or nil.

In Lua (e.g., in Conditions fields), a common check is:

Code: Select all

Variable["flag"] ~= true
This will check if the variable is false or nil.
User avatar
ds2497
Posts: 80
Joined: Wed Jun 14, 2023 2:13 am

Re: Watch Boolean Variables

Post by ds2497 »

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

Re: Watch Boolean Variables

Post by Tony Li »

Glad to help!
Post Reply