Page 1 of 1
How to change variables through script
Posted: Fri Aug 09, 2019 1:10 pm
by fanaei
Hi. I'm trying to change a variable with this code. The variable changes but when I try to use conditions based on this variable, it doesn't work fine! The variable shows that it's true but the condition recognize it false!
Code: Select all
for (int j = 0; j < DialogueManager.MasterDatabase.variables.Count; j++) {
if (DialogueManager.MasterDatabase.variables [j].Name == "MyVariable") {
DialogueManager.MasterDatabase.variables [j].InitialBoolValue = true;
}
}
Re: How to change variables through script
Posted: Fri Aug 09, 2019 1:32 pm
by Tony Li
Hi,
Do not change the dialogue database at runtime. Instead, change the Lua variable:
Code: Select all
DialogueLua.SetVariable("MyVariable", true);
Re: How to change variables through script
Posted: Sat Aug 10, 2019 2:35 am
by fanaei
Thanks. That worked
For getting dialogue text, I use this code:
Code: Select all
DialogueManager.MasterDatabase.GetConversation (...).GetDialogueEntry (...).currentDialogueText;
Should I change it too? Or it's okay?
Re: How to change variables through script
Posted: Sat Aug 10, 2019 7:27 am
by Tony Li
Hi,
Yes, that's correct. Since dialogue text doesn't change at runtime, the Dialogue System does not put it in Lua. This saves memory.
If your text contains
markup tags such as [var=
variable], use FormattedText.Parse to get a version of the text with the markup tags replaced with their values:
Code: Select all
var text = DialogueManager.MasterDatabase.GetConversation (...).GetDialogueEntry (...).currentDialogueText;
text = FormattedText.Parse(text);