Set Bool true via Dialouge?

Announcements, support questions, and discussion for the Dialogue System.
Hereder
Posts: 76
Joined: Mon Dec 21, 2020 2:53 am

Set Bool true via Dialouge?

Post by Hereder »

I might have asked in the past (sorry) - But is there a convinent way to set Bools to true/false via LUA?
So I can write a simple line of text in the Conditions tab and that send a signal to my script?

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

Re: Set Bool true via Dialouge?

Post by Tony Li »

Hi,

Yes, register "get" and "set" methods with Lua. This post has an example.
Hereder
Posts: 76
Joined: Mon Dec 21, 2020 2:53 am

Re: Set Bool true via Dialouge?

Post by Hereder »

Thanks!
so, in this case, ,if it was a bool, it looks like this? Sorry, I don't really understand even after reading that link you provided.

public bool intimidate;
public void GetIntimidateBool() { return intimidate; }
public void SetIntimidateBool(double value) { intimidate = value; }
Lua.RegisterFunction(nameof(GetIntimidateBool), this, SymbolExtensions.GetMethodInfo(() => GetIntimidateBool()));


Original:
public int intimidate;
public double GetIntimidateSkill() { return intimidate; }
public void SetIntimidateSkill(double value) { intimidate = value; }
Lua.RegisterFunction(nameof(GetIntimidateSkill), this, SymbolExtensions.GetMethodInfo(() => GetIntimidateSkill()));



And It should say this in the ConditionTab:

GetIntimidateBool(intimidate) == true


Thanks in advance!
User avatar
Tony Li
Posts: 21681
Joined: Thu Jul 18, 2013 1:27 pm

Re: Set Bool true via Dialouge?

Post by Tony Li »

Hi,

Really close! Try something like the code below. Note that the Lua.RegisterFunction() calls should be in an Awake() method if you're putting the script on the Dialogue Manager, or in an OnEnable() method if you're putting the script on a GameObject that only exists in a single scene.

Code: Select all

public bool intimidate;
public void GetIntimidateBool() { return intimidate; }
public void SetIntimidateBool(bool value) { intimidate = value; }

void Awake()
{
    Lua.RegisterFunction(nameof(GetIntimidateBool), this, SymbolExtensions.GetMethodInfo(() => GetIntimidateBool()));
    Lua.RegisterFunction(nameof(SetIntimidateBool), this, SymbolExtensions.GetMethodInfo(() => SetIntimidateBool(false)));
}
Hereder
Posts: 76
Joined: Mon Dec 21, 2020 2:53 am

Re: Set Bool true via Dialouge?

Post by Hereder »

Mm.. Return is underlined in Red...

I made a new script just for this function:

Code: Select all

using System.Collections;
using System.Collections.Generic;
using UnityEngine.SceneManagement;
using UnityEngine;
using UnityEngine.UI;
using PixelCrushers.DialogueSystem;
using System;

public class ConversationBools : MonoBehaviour
{

    public bool intimidate;
    public void GetIntimidateBool() { return intimidate; }
    public void SetIntimidateBool(bool value) { intimidate = value; }

    void Awake()
    {
        Lua.RegisterFunction(nameof(GetIntimidateBool), this, SymbolExtensions.GetMethodInfo(() => GetIntimidateBool()));
        Lua.RegisterFunction(nameof(SetIntimidateBool), this, SymbolExtensions.GetMethodInfo(() => SetIntimidateBool(false)));
    }

}


How would I set it up in the Inspector?
If the conversation goes:

"Do you want to intimidate him?

And I give the player 2 options.
Yes/No.
Once I press yes or no it should set the bool to true/False.
What do I write in the Conditions tab?

Image:
intmidate.png
intmidate.png (20.23 KiB) Viewed 724 times
Thanks!
User avatar
Tony Li
Posts: 21681
Joined: Thu Jul 18, 2013 1:27 pm

Re: Set Bool true via Dialouge?

Post by Tony Li »

Hi,

I updated the example scene in this post with code that demonstrates what we've been discussing.

You'll see that the conversation branches into a <Skill Check> node, followed by nodes whose Conditions check GetIntimidateBool(). The conversation will use one node if this function returns true, and it will use the other node if the function doesn't return true.

If you have any follow up questions, please reply here in this thread, not that thread.
Hereder
Posts: 76
Joined: Mon Dec 21, 2020 2:53 am

Re: Set Bool true via Dialouge?

Post by Hereder »

Im lost here:
Could the x < 0.5 and x >= 0.5 represent Yes and no?
I just want to send a bool to the SkillCheckExample script saying Yes/No.
THe skills stuff confuses me a little bit! :D
User avatar
Tony Li
Posts: 21681
Joined: Thu Jul 18, 2013 1:27 pm

Re: Set Bool true via Dialouge?

Post by Tony Li »

Hi,

Please look at the other scene and conversation. The 'x' variable is only used in the first skill example. I prepared the second skill example for you. It's in the "Skill Check Example 2" conversation. It doesn't use 'x' at all.
Hereder
Posts: 76
Joined: Mon Dec 21, 2020 2:53 am

Re: Set Bool true via Dialouge?

Post by Hereder »

Thanks.!
I'm one step closer to solving this now.
I was looking at Dialouge Exempel 1 and thus, I wasn't able to see the bools.
Now I see them, the only problem is that It won't allow me to press any button with GetIntimidateBool() == true attached.
to the Condition Field. So I'm unable to set the Bool to true, if that make sense.

Image attached:

Or would it be possible/easier just to send a public void function from the Condition field?
If thats possible.?
Attachments
intimidate2.png
intimidate2.png (215.92 KiB) Viewed 716 times
User avatar
Tony Li
Posts: 21681
Joined: Thu Jul 18, 2013 1:27 pm

Re: Set Bool true via Dialouge?

Post by Tony Li »

Hi,

In that example, I assumed you'd set the Intimidate bool elsewhere, such as ticking the component's Intimidate checkbox in the inspector.

However, if you want to set the bool inside a conversation, use the Script field. Example:
  • Menu Text: "Read the book <i>How to Bully Friends and Intimidate People</i>"
  • Script: SetIntimidateBool(true)
Post Reply