Page 1 of 1

Question about Lua Observer

Posted: Wed Jul 26, 2023 5:40 am
by fbthd1234
Hi.

I have a question about how to use Lua Observer.

In the document, there is only content about variables that I have designated myself as observers.
Like Variable['something'].

Is it possible to use the Lua expression to observe changes across all Variables in the database?
Like how to use an expression like Variable['ALL'].

If there is a way, I want you to give me a guide.
Thank you.

Re: Question about Lua Observer

Posted: Wed Jul 26, 2023 8:11 am
by Tony Li
Hi,

No, there isn't a way to do that. Lua is like C# in that respect. There's nothing in Unity's C# that will tell you when any variable in all scripts has changed.

You could write C# methods to change Lua variables. Something like:

Code: Select all

public void SetBool(string variableName, bool value)
{
    DialogueLua.SetVariable(variableName, value);
    Debug.Log($"{variableName} just changed to: {value}"); // Notify me that variable changed.
}
Then register that method with Lua and use it to set DS variables instead of Variable["foo"] = value.