Quest Condition Counting

Announcements, support questions, and discussion for Quest Machine.
Post Reply
fbit
Posts: 30
Joined: Fri Nov 30, 2018 9:30 am

Quest Condition Counting

Post by fbit »

Hello everybody!

I noticed QuestMachine uses a counting mechanism when checking if the conditions for a questnode etc. are met. However, it would be handy if QuestMachine could keep track of all the different conditions and only count a true condition if it had not already been true.

I refer to the following code in the class QuestConditionSet:

Code: Select all

private void OnTrueCondition()
        {
            numTrueConditions++;
            if (areConditionsMet) SetTrue();
        }
        
public bool areConditionsMet
        {
            get
            {
                if (conditionList == null || conditionList.Count == 0) return true;
                switch (conditionCountMode)
                {
                    case ConditionCountMode.All:
                        return (numTrueConditions >= conditionList.Count);
                    case ConditionCountMode.Any:
                        return (numTrueConditions > 0);
                    case ConditionCountMode.Min:
                        return (numTrueConditions >= minConditionCount);
                    default:
                        if (Debug.isDebugBuild) Debug.LogWarning("Quest Machine: Internal error. Unrecognized condition count mode '" + conditionCountMode + "'. Please contact the developer.");
                        return false;
                }
            }
        }
And to explain my problem a bit further: I want a questnode to become "true" when condition1 and condition2 are met. Currently, the questnode would also become "true" if condition1 is met two times and condition2 is still false.

I thought about removing true conditions from the quest condition set, but maybe you don't always want this behaviour... anyway, is it possible to add a feature like this or should I use custom quest conditions for that?
User avatar
Tony Li
Posts: 22106
Joined: Thu Jul 18, 2013 1:27 pm

Re: Quest Condition Counting

Post by Tony Li »

Hi,

A condition should only become true once. This will keep the count correct. However, the current version has a bug that's already fixed in the commits for the next update. The QuestCondition class has 3 methods: StartChecking(), StopChecking(), and SetTrue(). The base SetTrue() method is supposed to call StopChecking() but it wasn't. It does now.
fbit
Posts: 30
Joined: Fri Nov 30, 2018 9:30 am

Re: Quest Condition Counting

Post by fbit »

Hi Tony,
Tony Li wrote: Thu Jan 17, 2019 9:31 am The base SetTrue() method is supposed to call StopChecking() but it wasn't. It does now.
Ah, I see, thanks for the information!
fbit
Posts: 30
Joined: Fri Nov 30, 2018 9:30 am

Re: Quest Condition Counting

Post by fbit »

I've just found out that you can reset QuestConditionSet.numTrueConditions as it has a public setter!

So, in case anyone is interested:
if you want to have a QuestCondition that refreshes its state on a certain event, reset QuestConditionSet.numTrueConditions when the event is fired and do not call StopChecking() on that QuestCondition.

At least, this is what worked for me :D
Post Reply