Page 1 of 1

How can I control Quest State by the Boolean value of Toggle?

Posted: Sat Nov 20, 2021 10:34 am
by aliom
I want the player to select the correct answer from several Toggles and then click the OK button to complete the Quest. If the player selects the wrong answer the Quest will not be completed.
Pictures used to explain
Pictures used to explain
Xnip2021-11-21_00-19-35.jpg (153.98 KiB) Viewed 170 times
Now I use Dialogue System Trigger's OnUse() to set the Quest State to Success after the player selects the correct answer(the answer buttons has Toggle component), but this causes a problem. After the player has selected the correct answer once, the task remains as Success after the player selects the wrong answer and clicks the Confirm button.
I would like to ask if there is a way to control the Quest State by toggle's Boolean to achieve the functionality I want? Thanks.

Re: How can I control Quest State by the Boolean value of Toggle?

Posted: Sat Nov 20, 2021 11:18 am
by Tony Li
I'm sorry; I don't think I understand. But I'll try to provide some info.

It may be easiest to write a small script. For example, add a script like this to the Toggle, and configure the Toggle's OnValueChanged() UnityEvent to call the script's OnValueChanged method:

ToggleControlQuestState.cs

Code: Select all

using UnityEngine;
using PixelCrushers.DialogueSystem;

public class ToggleControlQuestState : MonoBehaviour
{
    [QuestPopup] public string quest;

    // If toggle is ticked, set quest state to success; otherwise set it to active.
    public void OnValueChanged(bool value)
    {
        if (value == true)
        {
            QuestLog.SetQuestState(quest, QuestState.Success);
        }
        else
        {
            QuestLog.SetQuestState(quest, QuestState.Active);
        }
    }
}

Re: How can I control Quest State by the Boolean value of Toggle?

Posted: Mon Nov 22, 2021 10:37 pm
by aliom
Tony Li wrote: Sat Nov 20, 2021 11:18 am I'm sorry; I don't think I understand. But I'll try to provide some info.

It may be easiest to write a small script. For example, add a script like this to the Toggle, and configure the Toggle's OnValueChanged() UnityEvent to call the script's OnValueChanged method:

ToggleControlQuestState.cs

Code: Select all

using UnityEngine;
using PixelCrushers.DialogueSystem;

public class ToggleControlQuestState : MonoBehaviour
{
    [QuestPopup] public string quest;

    // If toggle is ticked, set quest state to success; otherwise set it to active.
    public void OnValueChanged(bool value)
    {
        if (value == true)
        {
            QuestLog.SetQuestState(quest, QuestState.Success);
        }
        else
        {
            QuestLog.SetQuestState(quest, QuestState.Active);
        }
    }
}
Thank you very much. I will try it!