Page 1 of 1

Keep track of variables

Posted: Tue Nov 28, 2017 10:11 am
by hapciupalit
Hi I bought the asset a few days ago, and for some time I'm trying to understand how to keep track of my variables.
In conversation i call this function :

Code: Select all

Variable["Money"] = 100
And when I try to read it after is called in another object with this code I still got value 0:

Code: Select all

public DialogueDatabase database;

	void Update(){
		print(database.variables[0].fields[1].value);
	}
Image

So could you please help me understand what I do wrong

Re: Keep track of variables

Posted: Tue Nov 28, 2017 10:24 am
by Tony Li
Hi,

Thanks for buying the Dialogue System!

Use the DialogueLua.GetVariable function:

Code: Select all

using PixelCrushers.DialogueSystem;
...
void Update(){
	print(DialogueLua.GetVariable("Money").AsFloat);
}
Your dialogue database contains design-time data. At runtime, the Dialogue System loads the values of your dialogue database into a Lua environment so you can manipulate it. To access the runtime data, use the DialogueLua class.

You can read more about Lua here.

Re: Keep track of variables

Posted: Tue Nov 28, 2017 10:29 am
by hapciupalit
Thank you very much!

Re: Keep track of variables

Posted: Tue Nov 28, 2017 10:37 am
by Tony Li
Happy to help!

Re: Keep track of variables

Posted: Sat Dec 23, 2017 9:39 am
by namelesswc
Is there a onChangedEvent for variables one can subscribe to? E.g. I'm having a number variable "Money". In a script I want to get notified whenever the variable gets updated.

Re: Keep track of variables

Posted: Sat Dec 23, 2017 9:43 am
by Tony Li
Yes; you can add a Lua Observer, which lets you observe the return value of any expression, not just variables, for changes. For efficiency, it's best to set the frequency to EveryDialogueEntry or EndOfConversation.