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!
Watch Boolean Variables
Re: Watch Boolean Variables
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:
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:
Re: Watch Boolean Variables
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?
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!
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);
}
}
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!
Re: Watch Boolean Variables
Hi,
Related topic: How To: Handle Saved Game Versions
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:
This will check if the variable is false or nil.
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
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
Re: Watch Boolean Variables
Thank you very much!