Page 1 of 1

Suggesting Some Code Improvement

Posted: Tue Mar 16, 2021 12:24 pm
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

Re: Suggesting Some Code Improvement

Posted: Tue Mar 16, 2021 1:08 pm
by Tony Li
Hi,

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