Implementing new Predicates...?

I am a little confused on creating new Predicates. Let say for example, an ObjectiveComplete predicate… would the switch statement on QuestList, look something like this?

switch(predicate)
            {
                case "HasQuest":
                    return HasQuest(Quest.GetByName(parameters[0]));
                case "CompletedQuest":
                    return GetQuestStatus(Quest.GetByName(parameters[0])).IsComplete();
                case "ObjectiveComplete":
                    return GetQuestStatus(Quest.GetByName(parameters[0])).IsObjectiveComplete(parameters[1]);
            }
            return null;

I can seem to get this to return a parameter for the Objective, it comes back null, and wont continue from the root dialogue node to the Choice node.

That actually looks exactly right.

Paste up a screenshot of the Condition with the ObjectiveComplete.

Remember that without error checking, you’ll need to test for HasQuest before testing for ObjectiveComplete (or if you don’t have the quest, this will cause an error if you test the objective).

@Brian_Trotter ,Thank you for the response! I haven’t been able to test any further(I was at a family get together), but I have been thinking about this problem all day, and I think that is the reason I am getting the Null exception Error. I will post more, when Ive figured it out, or get more lost…lol. Thanks again!

Figured it out!

 public bool? Evaluate(string predicate, string[] parameters)
        {
           
            switch(predicate)
            {
                case "HasQuest":
                    return HasQuest(Quest.GetByName(parameters[0]));
                case "CompletedQuest":
                    if (HasQuest(Quest.GetByName(parameters[0])))
                    {
                        return GetQuestStatus(Quest.GetByName(parameters[0])).IsComplete();
                    }
                    return false;
                case "ObjectiveCompleted":
                    if (HasQuest(Quest.GetByName(parameters[0])))
                    {
                        return GetQuestStatus(Quest.GetByName(parameters[0])).IsObjectiveComplete(parameters[1]);
                    }
                    return false;
            }
            return null;
        }

I guess I should say, The objectiveComplete, should work the same way, just has to check that the player has the quest first. :slight_smile:

Edit: Tested with new predicate, it works.

1 Like

Well done!! I’ll be the first to admit that when we presented these courses, we didn’t do a lot of implementing error checking. It was discussed early in the courses, and every so often we mention it, but at the intermediate stage, it is something we should be mindful of. My general rule of thumb is that if there is any chance that something can be null, then it must be treated as a potential null reference and appropriate sanity checks should be implemented.

1 Like

The more complex conditions sort of handle this on their own… but it was definitely a good reminder to make sure checks are implemented. :slight_smile:

1 Like

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

Privacy & Terms