Lua check for bool true

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
hrohibil
Posts: 369
Joined: Thu Nov 04, 2021 12:50 pm

Lua check for bool true

Post by hrohibil »

Hello Tony

I have a public bool called radioFound which starts out as false.

Then after it becomes TRUE, I want to use Lua to check in the node tree that if this condition is true then start this node, but it never evaluates to true..

In the node Condition box I use this to check " setHasRadio = true"

Code: Select all

 public bool radioFound = false;
    private void Awake()
    {

        Lua.RegisterFunction(nameof(setHasRadio), this, SymbolExtensions.GetMethodInfo(() => setHasRadio()));

    }

    bool setHasRadio() { return radioFound; }
User avatar
Tony Li
Posts: 22085
Joined: Thu Jul 18, 2013 1:27 pm

Re: Lua check for bool true

Post by Tony Li »

Hi,

In the Conditions box, use:

Code: Select all

setHasRadio() == true
or just:

Code: Select all

setHasRadio()
If that doesn't work, are you sure radioFound is true? Since it's a serialized public variable, you can watch its value in the inspector.

Are there any errors or warnings in the Console window?

You can test the variable by entering this at the bottom of the Dialogue Editor's Watches tab and clicking Run:

Code: Select all

print(setHasRadio())
hrohibil
Posts: 369
Joined: Thu Nov 04, 2021 12:50 pm

Re: Lua check for bool true

Post by hrohibil »

Thank you Toni it worked.

But where exactly is the " bottom of the Dialogue Editor's Watches"??
User avatar
Tony Li
Posts: 22085
Joined: Thu Jul 18, 2013 1:27 pm

Re: Lua check for bool true

Post by Tony Li »

While playing in the Unity editor, go to the Dialogue Editor window's Watches tab. There's a field at the bottom of the window to enter Lua commands.
hrohibil
Posts: 369
Joined: Thu Nov 04, 2021 12:50 pm

Re: Lua check for bool true

Post by hrohibil »

Thank you Toni!!!
User avatar
Tony Li
Posts: 22085
Joined: Thu Jul 18, 2013 1:27 pm

Re: Lua check for bool true

Post by Tony Li »

Glad to help!
Post Reply