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
Access bool from own script
Re: Access bool from own script
Hi,
Use DialogueLua.GetVariable("variable-name").asBool:
Use DialogueLua.GetVariable("variable-name").asBool:
Code: Select all
bool talkedToAdam = DialogueLua.GetVariable("TalkedToAdam").asBool;
Re: Access bool from own script
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?
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?
Re: Access bool from own script
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.
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);
}
}
Re: Access bool from own script
Thank you Toni..
That did it !!!
I am so happy right now
That did it !!!
I am so happy right now
Re: Access bool from own script
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 ?
So if I pickup an item then I want to set a bool to true ?