Cure disease code help please

Started by rogerbacon, March 09, 2018, 08:43:05 PM

Previous topic - Next topic

rogerbacon

I have the following code that is causing an error.

var treatableInjuries = tracker.pawn.health.hediffSet.hediffs;
                if (treatableInjuries != null && treatableInjuries.Count() > 0)
                {
                    var sleepingSickness = treatableInjuries.FirstOrDefault(x => x.def.defName == "SleepingSickness"); // this line causes an error
                    if (sleepingSickness != null)
                    {
                        tracker.pawn.health.hediffSet.hediffs.Remove(sleepingSickness);
                    }
                }


For testing I've placed it on the Tick() event of the Doorpat mod. I use that for testing code because I can trigger it whenever a pawn walks on the door mat. This process has worked well in the past so I know it is not the problem. For example, the following code works fine


var traitPyro = pawn.story.traits.GetTrait(TraitDefOf.Pyromaniac);
                if (traitPyro != null)
                {
                    pawn.story.traits.allTraits.Remove(traitPyro);
                }


I forget the exact error message; it seemed fairly generic and not useful but I can look it up and post it if nobody can tell what I'm doing wrong from the code I've posted.
Thanks.