Page 1 of 1

Quest Doesn't Continue when Conditions Met Out of Order

Posted: Thu Aug 11, 2022 11:36 pm
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!

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

Posted: Fri Aug 12, 2022 8:02 am
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 758 times

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

Posted: Fri Aug 12, 2022 9:31 am
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!

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

Posted: Fri Aug 12, 2022 1:43 pm
by Tony Li
Glad to help!