Page 1 of 1

Question About QuestCondition

Posted: Thu Jun 03, 2021 6:02 am
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.

Re: Question About QuestCondition

Posted: Thu Jun 03, 2021 6:05 am
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?

Re: Question About QuestCondition

Posted: Thu Jun 03, 2021 4:59 pm
by Tony Li
(Moved to bug report here.)