Suggesting Some Code Improvement

Announcements, support questions, and discussion for Quest Machine.
Post Reply
AArtlone
Posts: 37
Joined: Tue Mar 09, 2021 2:54 am

Suggesting Some Code Improvement

Post by AArtlone »

Hi, it's me again haha.

Just another thing that I have found and wanted to share.

Remember we talked about the NullException error that would happen if no Urgencies Functions were assigned to any of the Entities, thus it would fail to Determine the Goal?

I have realized that you actually included a Debug for it, but it is positioned after the coroutine breaks, thus it does not get to the Debug statement.

In the QuestGenerator script, in the DetermineGoal()
Code:

Code: Select all

// Search world model for most urgent fact:
Fact[] mostUrgentFacts;
var cumulativeUrgency = worldModel.ComputeUrgency(goalSelectionMode, out mostUrgentFacts, ignoreList, detailedDebug);
var mostUrgentFact = ChooseWeightedMostUrgentFact(mostUrgentFacts);
if (mostUrgentFact == null) yield break;
if (cumulativeUrgency <= 0)
{
	if (QuestMachine.debug || detailedDebug) Debug.Log("Quest Machine: [Generator] " + entity.displayName + 
	": No facts are currently urgent for " + entity.displayName + ". Not generating a new quest.", entity);
	yield break;
}
I think it should be changed to this:

Code: Select all

// Search world model for most urgent fact:
Fact[] mostUrgentFacts;
var cumulativeUrgency = worldModel.ComputeUrgency(goalSelectionMode, out mostUrgentFacts, ignoreList, detailedDebug);
var mostUrgentFact = ChooseWeightedMostUrgentFact(mostUrgentFacts);
if (cumulativeUrgency <= 0)
{
	if (QuestMachine.debug || detailedDebug) Debug.Log("Quest Machine: [Generator] " + entity.displayName + 
	": No facts are currently urgent for " + entity.displayName + ". Not generating a new quest.", entity);
	yield break;
}
if (mostUrgentFact == null) yield break;
Hope you find this helpful.

Artem
User avatar
Tony Li
Posts: 21925
Joined: Thu Jul 18, 2013 1:27 pm

Re: Suggesting Some Code Improvement

Post by Tony Li »

Hi,

Thanks! That will be more informative for developers. I'll move that line.
Post Reply