Problem with Predicates returning random results

I’ve created an NPCInventory script so that the NPC’s can hold items in a list. I have included the ISaveable interface so that this list of items is saved and loaded and that is working fine, however I also included the Interface IPredicateEvaluator so that I can display certain dialogues if the NPC does or does not have certain items in their list of items. The problem is the Evaluator seems to produce random results, and it is hard to debug as to why. My Evaluator is based off of the Player’s Inventory.cs and that seems to Evaluate correctly if I have a dialogue checking if a Player has a certain item in their inventory…

Here is the NPC’s Evaluator, I’m not sure where to look or how to debug this…

My only thought was perhaps the game does not have a reference for which NPC you’re referring to…

Any help would be great. thanks

public bool? Evaluate(PredicateType predicate, string[] parameters)
    {
        switch (predicate)
        {
            case PredicateType.NPCHasItem:
                for (int i = 0; i < parameters.Length; i++)
                {
                    InventoryItem itemParameter = InventoryItem.GetFromID(parameters[i]);
                    if (NPCHasItem(itemParameter))
                    {
                        return true;
                    }
                }
                return false;

            case PredicateType.NPCHasItems: //Only works for stackable items.
                InventoryItem item = InventoryItem.GetFromID(parameters[0]);
                int stack = FindStack(item);
                if (stack == -1) return false;
                if (int.TryParse(parameters[1].ToString(), out int result))
                {
                    return inventoryItems[stack].number >= result;
                }
                return false;
        }

        return null;
    }

That’s pretty much it… The IPredicateEvaluators called in PlayerConversant are all from the GetComponents<IPredicateEvaluator>() which only pulls the evaluators from the Player. If you put Debugs in this Evaluate, you’ll find that they never fire.

You’ll need to find a way to let the PlayerConversant know that you want to test against the Speaker, not the player… Perhaps a boolean in the Condition “IsAIConversant”… if this is checked, run the query against the AIConversant’s IPredicateEvaluators instead of the player’s IPredicateEvaluators.

Thank you, yes that explains why my debug logs were never visible. I thought that was a limitation of the Predicate system lol. I actually do have a ‘IsAIConversant’ bool used elsewhere, I should be able to add your suggested changes and get it working now.

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

Privacy & Terms