CompletedQuest

So I have a problem with the CompletedQuest predicate.

I have three different player options. First when he has completed the quest and two different ones without any predicate. but somehow he is always shooting me this mistake.

NullReferenceException: Object reference not set to an instance of an object
RPG.Quests.QuestList.Evaluate (System.String predicate, System.String parameters) (at Assets/Scripts/Quests/QuestList.cs:107)

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

            return null;
        }
    }

I think this is your culprit. If the Player has never accepted the quest, then there is no QuestStatus.
Try this:

case "CompletedQuest":
if(!HasQuest(Quest.GetByName(parameters[0])); return false;
return GetQuestStatus(Quest.GetByName(parameters[0])).IsComplete();

That did the trick, thank you!

A quick note on this: We didn’t do a lot of null checking in this course, especially with conditions. That’s left to you guys with this in mind: If it can be null, check for null. :slight_smile:

1 Like

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

Privacy & Terms