List<Custom> IExposable and PostExposeData

Started by ethouiche, February 11, 2018, 07:11:09 PM

Previous topic - Next topic

ethouiche

Hello,

I have a comp class that uses another class as a list. I cant manage to save properly the list generated in the comp class. I have used many ExposeData before but never with a list. I need this list.

public class LTF_PawnSnapshot : IExposable
{
        // should send a signal to bench when dies instead of benchscan
        public Pawn original;

        public string pawnThingId;
        public string name;

        public float ageBiological;
        public Gender sex;

        //long ageChronological;
        public List<Hediff> hediffs;
        public List<SkillRecord> skills;


        //Race though
        public int cloneNum;
        public int AAA;

        public Building drillDep;

        public float buildProgress;
        public float buildAmount;

        public void ExposeData()
        {
            Scribe_References.Look<Pawn>(ref original, "LTF_snapOriginal");

            Scribe_Values.Look<string>(ref pawnThingId, "LTF_cloneOriginalId");
            Scribe_Values.Look<string>(ref name, "LTF_cloneOriginalName");

            Scribe_Values.Look< float>(ref ageBiological, "LTFOriginalAge");
            Scribe_Values.Look<Gender>(ref sex, "LTFOriginalSex");

            Scribe_Collections.Look<Hediff>(ref hediffs, "LTFOriginalHediff");
            //Scribe_Collections.LookList<Hediff>(ref hediffs, "LTFOriginalHediff");
            Scribe_Collections.Look<SkillRecord>(ref skills, "LTFOriginalSkill");
           
            Scribe_Values.Look<int>(ref cloneNum, "LTFcloneNum");
            Scribe_Values.Look<int>(ref AAA, "LTFcloneAAA");

            Scribe_References.Look<Building>(ref drillDep, "LTF_drillDep");

            Scribe_Values.Look<float>(ref buildProgress, "LTF_cloneWProgress");
            Scribe_Values.Look<float>(ref buildAmount, "LTF_cloneWAmount");
        }
    }


The comp Class with the list;
        // Scanned
        List<LTF_PawnSnapshot> RegisteredPawns = new List<LTF_PawnSnapshot>();
[...]

        public override void PostExposeData()
        {
            base.PostExposeData();

            //Scribe_Collections.Look(ref RegisteredPawns, "LTF_snaps", LookMode.Undefined, new object[0]);

            //Scribe_Deep.Look(ref RegisteredPawns, "LTF_snaps");
            //Scribe_Collections.Look(ref RegisteredPawns, "LTF_snaps",LookMode.Reference);
            //Scribe_Collections.Look(ref RegisteredPawns, "LTF_snaps", LookMode.Deep);
            //Scribe_Collections.Look<LTF_PawnSnapshot>(ref RegisteredPawns, "LTF_snaps", LookMode.Deep);
            //update

        }


I have tried many options without success. I really feel i have no idea what i am doing. I have cast errors either when i load or when i save.

Please be my savior.
Good day.

Jaxxa

You might have more luck if you could upload the mod so we can run it and see what happens for our self.

ethouiche

        public override void PostExposeData()
        {
            base.PostExposeData();
            Scribe_References.Look(ref bloodGiver, "LTF_BloodGiver");
            Scribe_Values.Look(ref scanProgress, "LTF_PhenotypeScanProgress");

            Scribe_Collections.Look<LTF_PawnSnapshot>(ref RegisteredPawns, "LTF_snaps", LookMode.Undefined, new object[0]);
            if (Scribe.mode == LoadSaveMode.PostLoadInit && this.RegisteredPawns == null)
            {
                this.RegisteredPawns = new List<LTF_PawnSnapshot>();
            }
}


(Filename: C:/buildslave/unity/build/artifacts/generated/common/runtime/DebugBindings.gen.cpp Line: 51)

Could not do PostLoadInit: System.NullReferenceException: Object reference not set to an instance of an object
  at Verse.Hediff.ExposeData () [0x00000] in <filename unknown>:0
  at Verse.HediffWithComps.ExposeData () [0x00000] in <filename unknown>:0
  at Verse.PostLoadIniter.DoAllPostLoadInits () [0x00000] in <filename unknown>:0


I have been told the game does not know how to handle/save the hediff data because it's not attached to a pawn.  :-\

ethouiche

By using a pawn to handle the hediff it seems the save works fine.