Hi Tony,
I want to update the number of credits the player has after they purchase something.
Right now I have a text field that loads the number of credits on the scene start, and I would like a simple observer similar to the condition observer but that triggers whenever the dialogue system variable "Credits" changes.
I was looking at the LuaWatchItem class but I'm not too sure how to implement it. Was hoping for some pointers or an example. Thank you!
Simple Observer for a Dialogue System Variable
Re: Simple Observer for a Dialogue System Variable
Hi,
How are you changing the Dialogue System variable "Credits"? In a conversation? In a custom script?
How are you changing the Dialogue System variable "Credits"? In a conversation? In a custom script?
Re: Simple Observer for a Dialogue System Variable
Hi Tony,
I am accessing Credits though a lua command.
The code runs OnEnable. I thought about updating the value on the update loop, but would prefer to do it some other way.
I am accessing Credits though a lua command.
Code: Select all
int value = Lua.Run("return Variable['" + variableName + "']").asInt;
title.text = value.ToString();
Re: Simple Observer for a Dialogue System Variable
Hi,
The DialogueLua class provides an easier way to get variable values:
However, a Lua Observer might be easier:
One or two of these is fine, but they're not ideally efficient because they poll the value every update and then call the function (OnCreditsChanged) if the value has changed. If you need a lot of them, or if you need to squeeze every last nanosecond out of performance, you can register a Lua function. I can describe that process if you need it.
The DialogueLua class provides an easier way to get variable values:
Code: Select all
int value = DialogueLua.GetVariable("Credits").asInt;
Code: Select all
void OnEnable()
{
// Initialize text:
title.text = DialogueLua.GetVariable("Credits").asString;
// Add observer:
DialogueManager.AddLuaObserver("Variable['Credits']", LuaWatchFrequency.EveryUpdate, OnCreditsChanged);
}
void OnCreditsChanged(LuaWatchItem luaWatchItem, Lua.Result newValue)
{
title.text = newValue.asString; // Get .asInt if you want the actual numeric value, too.
}
Re: Simple Observer for a Dialogue System Variable
Hi Tony,
Thanks for the examples. I ended up using Unity events to call the methods I needed upon buying things.
I didn't know about DialogueLua, I will definitely be using that from now on. Thanks!
Thanks for the examples. I ended up using Unity events to call the methods I needed upon buying things.
I didn't know about DialogueLua, I will definitely be using that from now on. Thanks!