Question About QuestCondition

Announcements, support questions, and discussion for Quest Machine.
Post Reply
AArtlone
Posts: 37
Joined: Tue Mar 09, 2021 2:54 am

Question About QuestCondition

Post by AArtlone »

Hi!

I require some help with the QuestConditon.

What I was trying to achieve, is to have a custom QuestCondition which in StartChecking() would check if the condition is already true, and if it is, then calls SetTrue().

Code: Select all

    public override void StartChecking(System.Action trueAction)
    {
        base.StartChecking(trueAction);

        //if (AlreadyTrue())
        //{
        //    SetTrue();
        //    return;
        //}

        Subscribe();
    }
For example, I want to create a condition that checks if the player has a magic Wand. Let's imagine that the player had found the wand before. Then when the Quest starts, the condition has to check if ht player already has the Wand. How would you go about that?

I am using this custom QuestCondition as an AutoStartCondition.

The problem with my approach is that it causes a StackOverflow error in this bit of the code:

Code: Select all

public void BecomeOfferable()
        {
            try
            {
                QuestState state = GetState();
                Debug.Log(state);

                if (GetState() != QuestState.WaitingToStart) 
                    SetState(QuestState.WaitingToStart);

                questOfferable(this);
                SetQuestIndicatorState(questGiverID, QuestIndicatorState.Offer);
            }
            catch (Exception e) // Don't let exceptions in user-added events break our code.
            {
                if (Debug.isDebugBuild) Debug.LogException(e);
            }
        }
Since the condition returns true, the Quest becomes active. Then in BecomeOfferable it checks if it is not equal to WaitingToStart (which it is not) thus sets it to WaitingToStart, which calls SetState() and consequently SetStartChecking(true).

Please let me know if the above explanation is clear.
AArtlone
Posts: 37
Joined: Tue Mar 09, 2021 2:54 am

Re: Question About QuestCondition

Post by AArtlone »

Right after I have posted this issue, I have checked the CounterQuestCondition and found that it uses almost the same approach. Thus, my question is, do you know why my approach causes the error?
User avatar
Tony Li
Posts: 22104
Joined: Thu Jul 18, 2013 1:27 pm

Re: Question About QuestCondition

Post by Tony Li »

(Moved to bug report here.)
Post Reply