[BUG] (Alpha 11) Psychic soothe throws null ref exception when no Need_Mood

Started by mipen, June 14, 2015, 07:08:41 AM

Previous topic - Next topic

mipen

Having colony members that do not have a Need_Mood causes a null reference exception when the Psychic Soothe event fires. This happens here:


protected override bool StorytellerCanUseNowSub()
{
if (!base.StorytellerCanUseNowSub())
{
return false;
}
float num = 0f;
List<Pawn> list = Find.ListerPawns.PawnsInFaction(Faction.OfColony);
for (int i = 0; i < list.Count; i++)
{
num += list[i].needs.mood.CurLevel; <---Here!
}
float num2 = num / (float)list.Count;
return num2 < 0.36f;
}


Proposed solution: Add null checks to check whether the pawn has a Need_Mood

StorymasterQ

ALWAYS CHECK FOR NULL.

I propose renaming the Null entity. We all know a better name for null. Then, IDEs all around the world can throw a new error: "There is no object, only Zuul."
I like how this game can result in quotes that would be quite unnerving when said in public, out of context. - Myself

The dubious quotes list is now public. See it here

Tynan

This is a modding support request, right? There's no way to do this in vanilla?

FYI Storymaster, "always check for null" is actually very poor advice. All you'll do is hide bugs so they show up in subtler and harder-to-trace ways. It's best to make bugs obvious immediately, by throwing a null ref exception if appropriate.
Tynan Sylvester - @TynanSylvester - Tynan's Blog

StorymasterQ

Quote from: Tynan on June 16, 2015, 03:15:41 AM
FYI Storymaster, "always check for null" is actually very poor advice. All you'll do is hide bugs so they show up in subtler and harder-to-trace ways. It's best to make bugs obvious immediately, by throwing a null ref exception if appropriate.

Yes, that's what I meant. Check for null, and when they show up throw a ZuulRefException as I mentioned.
I like how this game can result in quotes that would be quite unnerving when said in public, out of context. - Myself

The dubious quotes list is now public. See it here

mipen

Yeah I guess it is for modding, though it's caused by simply changing the intelligence to ToolUser which stops the pawn from being given a mood need

Tynan

I can't support this for now. It's not just the psychic soothe, that's the the first of dozens of places that would break if you had a colonist who wasn't Humanlike.

I'm afraid non-Humanlike colonists aren't officially supported by now. When they are (e.g. pets) they'll be a different class of pawns associated with the colony, not "real" colonists. Sorry my man.
Tynan Sylvester - @TynanSylvester - Tynan's Blog