Foot cream still in inventory after the drop

The foot cream does NOT appear to come out of the Dialogue/Quest

After I drop
I go back to guard
Guard still thinks I have foot cream

ouch…

In fact this time
I stopped the game

DID NOT SAVE

Started game back up Did NOT have quest and the Dialogue (see pic below) still thought I had foot cream
footcreamError15OnGameDev

Thanks for any help on this

Conditions are the trickiest thing in our game to debug. Worth it once it’s nailed down.

Looks like I may need more than the Inventory.Evaluate() method…

Can you post your Condition.cs script here, along with the Evaluates from both QuestList and InventoryItem (I asked you for the InventoryItem.Evaluate() method on the other post, but I think I’ll need to see all three together in the same post to try to get a picture of what’s happening.

Sure happy to.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

namespace RPG.Core
{
    [System.Serializable]
    public class Condition
    {
        [SerializeField]
        Disjunction[] and;

        public bool Check(IEnumerable<IPredicateEvaluator> evaluators)
        {
            foreach (Disjunction dis in and)
            {
                if (!dis.Check(evaluators))
                {
                    return false;
                }
            }
            return true;
        }

        [System.Serializable]
        class Disjunction
        {
            [SerializeField]
            Predicate[] or;

            public bool Check(IEnumerable<IPredicateEvaluator> evaluators)
            {
                foreach (Predicate pred in or)
                {
                    if (pred.Check(evaluators))
                    {
                        return true;
                    }
                }
                return false;
            }
        }

        [System.Serializable]
        class Predicate
        {
            [SerializeField]
            PredicateEnum predicate;
            [SerializeField]
            string[] parameters;
            [SerializeField]
            bool negate = false;

            public bool Check(IEnumerable<IPredicateEvaluator> evaluators)
            {
                foreach (var evaluator in evaluators)
                {
                    bool? result = evaluator.Evaluate(predicate, parameters);
                    if (result == null)
                    {
                        continue;
                    }
                    else
                    {
                        Debug.Log($"predicate is {predicate} and the parameters are {parameters}");
                    }

                    if (result == negate) return false;
                }
                return true;
            }
        }
    }
}
------------------------------------------*******************END CONDITION.CS

Evaluate() Methods below.... Note I only have 2
QuestList.cs version
        public bool? Evaluate(PredicateEnum predicate, string[] parameters)
        {
            switch (predicate)
            {
                case PredicateEnum.HasQuest: 
                    return HasQuest(Quest.GetByName(parameters[0]));
                case PredicateEnum.HasInventoryItem:
                    return HasQuest(Quest.GetByName(parameters[0]));
                case PredicateEnum.CompletedQuest:
                    // if(parameters[0]==null) return false;
                    // Quest questToTest = Quest.GetByName(parameters[0]);
                    // if(questToTest==null) return false;
                    // if(!HasQuest(questToTest)) return false; 
                    
                    return GetQuestStatus(Quest.GetByName(parameters[0])).IsComplete();
                case PredicateEnum.None:
                    return null;
            }

            return null;
        }
Inventory.cs version
        public bool? Evaluate(PredicateEnum predicate, string[] parameters)
        {
            //Debug.Log($"Evaluate the Inventory.cs: {predicate}");
            switch (predicate)
            {
                case PredicateEnum.HasInventoryItem:
                    //Debug.Log($"Evaluate the Inventory.cs: {parameters[0]}");
                    Debug.Log($"HasItem is: {HasItem(InventoryItem.GetFromID(parameters[0]))} and its ID is {parameters[0]}");
                    return HasItem(InventoryItem.GetFromID(parameters[0]));

                case PredicateEnum.HasInventoryItems:
                    // Debug.Log($"Evaluate the Inventory.cs: {parameters[0]}");
                    // Debug.Log($"HasItem is: {HasItem(InventoryItem.GetFromID(parameters[0]))}");
                    int quantity = 0;
                    if(int.TryParse(parameters[1], out quantity))
                    {
                        Debug.Log($"quantity = {quantity}");
                    }
                    int slot;
                    InventoryItem item = InventoryItem.GetFromID(parameters[0]);
                    if (HasItem(item, out slot))
                    {
                        if(GetNumberInSlot(slot) < int.Parse(parameters[1]))
                        {
                            return false;
                        }
                    }
                    else
                    {
                        return false;
                    }
                    return true;
                    //return HasItem(InventoryItem.GetFromID(parameters[0]));
            }

            return null;
        }

		

Google slides of screen shots from earlier

Pics of Inspector

What video did we add an Evaluate to the InventoryItem.cs?

I do not have that and I have watched these videos more than once each

Thanks

PS: Could that be my problem?

I was 1/2 asleep when I wrote the post, I’d meant to post Inventory. I believe, however, that I have found the issue… take a look at the Evaluate for QuestList.cs…

case PredicateEnum:HasInventoryItem:
     return HasQuest(Quest.GetByName(parameters[0]));

Questlist shouldn’t be resolving any HasInventoryItem predicates, that’s Inventory’s job. Believe it or not, I missed this three times reading over your code. I was ready to add more debugs for you to put in Condition and as I was typing it I looked up and noticed it.

So here’s what’s happening: Inventory is returning that HasItem is true, but QuestList is returning that HasItem is false, and Questlist is winning the race.

I suspect removing that case will resolve the issue.

Thanks for this it makes sense.

Still wondering HOW to make it work with unity(my designer ask me ok, How do i set this up)
I want to create a quest with 2 obj.
LIKE IN THE SLIDES
What scripts need to be on what gameObjects?
Can I complete an Objective From a PIckup gemaObject?

I am unable to answer my designers because I have not seen a complete example.
If I had I would be able to make that SLIDE SHOW correctly.

Seems we have TWO places to evaluate
my PredicateEnum has 4 things

    public enum PredicateEnum
    {
        None,
        HasQuest,
        HasInventoryItem,
        HasInventoryItems,
        CompletedQuest
    }

Of the 4 that would require thought
QuestList should handle HasQuest and CompleteQuest.

ok… Which character should be dragged into the dialogue trigger in order to have the QuestList available?
What script should be dragged under the dialogue trigger?

Inventory should handle HasInventoryItem or HasInventoryItems
ok… Which character should be dragged into the dialogue trigger in order to have the Inventory script available?
What script should be dragged under the dialogue trigger?

not to mention what needs to be on what dialogue node… I will get to that later when I understand better how to set up the HIERARCHY, I have to get those slides together so my designer knows how to use what we have.

1 step at a time.

Thanks for your help on this Brian

QuestList.cs
        public bool? Evaluate(PredicateEnum predicate, string[] parameters)
        {
            switch (predicate)
            {
                case PredicateEnum.HasQuest: 
                    return HasQuest(Quest.GetByName(parameters[0]));
                // case PredicateEnum.HasInventoryItem:
                //     return HasQuest(Quest.GetByName(parameters[0]));
                case PredicateEnum.CompletedQuest:
                    if(parameters[0]==null) return false;
                    Quest questToTest = Quest.GetByName(parameters[0]);
                    if(questToTest==null) return false;
                    if(!HasQuest(questToTest)) return false; 
                    
                    return GetQuestStatus(Quest.GetByName(parameters[0])).IsComplete();
                case PredicateEnum.None:
                    return null;
            }

            return null;
        }
		
Inventory.cs
        public bool? Evaluate(PredicateEnum predicate, string[] parameters)
        {
            //Debug.Log($"Evaluate the Inventory.cs: {predicate}");
            switch (predicate)
            {
                case PredicateEnum.HasInventoryItem:
                    //Debug.Log($"Evaluate the Inventory.cs: {parameters[0]}");
                    Debug.Log($"HasItem is: {HasItem(InventoryItem.GetFromID(parameters[0]))} and its ID is {parameters[0]}");
                    return HasItem(InventoryItem.GetFromID(parameters[0]));

                case PredicateEnum.HasInventoryItems:
                    // Debug.Log($"Evaluate the Inventory.cs: {parameters[0]}");
                    // Debug.Log($"HasItem is: {HasItem(InventoryItem.GetFromID(parameters[0]))}");
                    int quantity = 0;
                    if(int.TryParse(parameters[1], out quantity))
                    {
                        Debug.Log($"quantity = {quantity}");
                    }
                    int slot;
                    InventoryItem item = InventoryItem.GetFromID(parameters[0]);
                    if (HasItem(item, out slot))
                    {
                        if(GetNumberInSlot(slot) < int.Parse(parameters[1]))
                        {
                            return false;
                        }
                    }
                    else
                    {
                        return false;
                    }
                    return true;
                    //return HasItem(InventoryItem.GetFromID(parameters[0]));
            }

            return null;
        }

It might help if you download the example project from the Git against the lecture (Don’t get the latest repo, because he changed it in the middle of the Shops and Abilities course, go to the current lecture’s commit and then files, then Download Zip. Sam has the components installed on the Quest Givers, etc.

This topic was automatically closed 20 days after the last reply. New replies are no longer allowed.

Privacy & Terms