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

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
aliom
Posts: 4
Joined: Sat Nov 13, 2021 3:06 am

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

Post 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 181 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.
User avatar
Tony Li
Posts: 22158
Joined: Thu Jul 18, 2013 1:27 pm

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

Post 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);
        }
    }
}
aliom
Posts: 4
Joined: Sat Nov 13, 2021 3:06 am

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

Post 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!
Post Reply