Question about Lua Observer

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
fbthd1234
Posts: 10
Joined: Wed Jun 28, 2023 6:16 am

Question about Lua Observer

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

Re: Question about Lua Observer

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