Keep track of variables

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
hapciupalit
Posts: 24
Joined: Tue Nov 28, 2017 10:04 am

Keep track of variables

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

Re: Keep track of variables

Post 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.
hapciupalit
Posts: 24
Joined: Tue Nov 28, 2017 10:04 am

Re: Keep track of variables

Post by hapciupalit »

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

Re: Keep track of variables

Post by Tony Li »

Happy to help!
namelesswc
Posts: 7
Joined: Wed Nov 22, 2017 9:01 am

Re: Keep track of variables

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

Re: Keep track of variables

Post 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.
Post Reply