How to change variables through script

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
fanaei
Posts: 73
Joined: Wed Aug 15, 2018 10:38 am

How to change variables through script

Post 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;
			}
		}
User avatar
Tony Li
Posts: 22055
Joined: Thu Jul 18, 2013 1:27 pm

Re: How to change variables through script

Post by Tony Li »

Hi,

Do not change the dialogue database at runtime. Instead, change the Lua variable:

Code: Select all

DialogueLua.SetVariable("MyVariable", true);
fanaei
Posts: 73
Joined: Wed Aug 15, 2018 10:38 am

Re: How to change variables through script

Post 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?
User avatar
Tony Li
Posts: 22055
Joined: Thu Jul 18, 2013 1:27 pm

Re: How to change variables through script

Post 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);
Post Reply