Quest Doesn't Continue when Conditions Met Out of Order

Announcements, support questions, and discussion for Quest Machine.
Post Reply
cptscrimshaw
Posts: 113
Joined: Sun Sep 20, 2020 8:21 pm

Quest Doesn't Continue when Conditions Met Out of Order

Post by cptscrimshaw »

Hi Tony,

I'm running into an issue where the quest works completely fine if you do everything in the right order, but if conditions are met out of order (i.e., you get an item in your inventory before the quest asks you to), then it doesn't continue.

Here's my setup:
https://ibb.co/XWn2L8G

1. First condition to be met: https://ibb.co/k8S1pyp
2. Second condition to be met: https://ibb.co/gF9FcTJ
3. Node to make sure that both are met: https://ibb.co/tpMLD1S

Any idea why the "Found All Items" isn't registering as true when the previous conditions were met? For example, you can accomplish all of the above items even before getting the quest.

Here is my custom code for HasRecipe:

Code: Select all

using UnityEngine;
using System;

namespace PixelCrushers.QuestMachine
{
    public class HasRecipe : QuestCondition // Rename this class.
    {
        public StringField recipeName = new StringField();

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

            if (IsTrue())
            {
                SetTrue();
            }
            else
            {
                EventHandler.PlayerRecipeAdded += PlayerRecipeAdded;
            }
        }

        private bool IsTrue()
        {
            foreach (var recipe in Statics.player.GetComponent<CharacterCraftingData>().playerRecipes)
            {
                if (recipe.name == recipeName.text)
                {
                    QuestMachineMessages.RefreshUIs(this);
                    return true;
                }
            }
            return false;
        }

        private void PlayerRecipeAdded(string recipe)
        {
            recipeName.text = recipe;

            if (IsTrue())
            {
                SetTrue();
            }
        }

        public override void StopChecking()
        {
            base.StopChecking();
            EventHandler.PlayerRecipeAdded -= PlayerRecipeAdded;
        }
    }
}
This works perfectly fine if you do everything in the correct order, but I'd like the player to be able to complete items in any order they want. Am I missing something?

Thanks!
User avatar
Tony Li
Posts: 21925
Joined: Thu Jul 18, 2013 1:27 pm

Re: Quest Doesn't Continue when Conditions Met Out of Order

Post by Tony Li »

Hi,

Does it work if you change the Found All Items node's Conditions to Parents: All True? This will help narrow down what the issue is.

parentsTrue.png
parentsTrue.png (24.27 KiB) Viewed 736 times
cptscrimshaw
Posts: 113
Joined: Sun Sep 20, 2020 8:21 pm

Re: Quest Doesn't Continue when Conditions Met Out of Order

Post by cptscrimshaw »

Simple fixes are the best! I tried a few different ways of completing the quest, and now it works just fine with the Parents condition, which is way easier anyway :)

Thanks Tony!
User avatar
Tony Li
Posts: 21925
Joined: Thu Jul 18, 2013 1:27 pm

Re: Quest Doesn't Continue when Conditions Met Out of Order

Post by Tony Li »

Glad to help!
Post Reply