Access bool from own script

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

Access bool from own script

Post by hrohibil »

Hello Toni

If I set a bool to to be true in one of m dialogues, how do i access this bool from my own custom script where I just ant to check if that bool is true then i do something in my script..

Thanks
User avatar
Tony Li
Posts: 21721
Joined: Thu Jul 18, 2013 1:27 pm

Re: Access bool from own script

Post by Tony Li »

Hi,

Use DialogueLua.GetVariable("variable-name").asBool:

Code: Select all

bool talkedToAdam = DialogueLua.GetVariable("TalkedToAdam").asBool;
hrohibil
Posts: 368
Joined: Thu Nov 04, 2021 12:50 pm

Re: Access bool from own script

Post by hrohibil »

Forgive me Toni.

I am a noob.

I pasted that code in the conversations sequence field, and conditions field but that did not help.
In variables I have a bool set to false called "gunMap".
In the conversation field script I have this currently:

Variable["gunMap"] = true

What i am trying to do is to enable a script or a gameObject when the bool is true....

So my two noob questions:

1:
Where and how i insert that code?

2:
And how do i reference to it from my own script?
User avatar
Tony Li
Posts: 21721
Joined: Thu Jul 18, 2013 1:27 pm

Re: Access bool from own script

Post by Tony Li »

hrohibil wrote: Wed Mar 09, 2022 5:15 pmIn the conversation field script I have this currently:

Variable["gunMap"] = true

What i am trying to do is to enable a script or a gameObject when the bool is true....
In the same dialogue entry node's Sequence field, you can use SetEnabled() to enable a script or SetActive() to activate a GameObject. See the Cutscene Sequence Tutorials and Sequence Command Reference for more info.
hrohibil wrote: Wed Mar 09, 2022 5:15 pm1: Where and how i insert that code?
2: And how do i reference to it from my own script?
Insert it where you want to check the value of the variable. I don't know the script, so I can't tell you any more than that. Here's an example:

Code: Select all

public class SomeScript : MonoBehaviour
{
    public void CheckVariableValue()
    {
        bool gunMap = DialogueLua.GetVariable("gunMap").asBool;
        Debug.Log("The current value of gunMap is: " + gunMap);
    }
}
hrohibil
Posts: 368
Joined: Thu Nov 04, 2021 12:50 pm

Re: Access bool from own script

Post by hrohibil »

Thank you Toni..

That did it !!!

I am so happy right now :-)
hrohibil
Posts: 368
Joined: Thu Nov 04, 2021 12:50 pm

Re: Access bool from own script

Post by hrohibil »

Oh and what about the other way around. Instead of GetVariable can I somehow setVariable ?

So if I pickup an item then I want to set a bool to true ?
User avatar
Tony Li
Posts: 21721
Joined: Thu Jul 18, 2013 1:27 pm

Re: Access bool from own script

Post by Tony Li »

Yes. SetVariable():

Code: Select all

DialogueLua.SetVariable("gunMap", true);
Post Reply