Ludeon Forums

RimWorld => Mods => Topic started by: battlemage64 on January 15, 2020, 07:32:07 PM

Title: How to save a variable?
Post by: battlemage64 on January 15, 2020, 07:32:07 PM
I have two (possibly three) IDictionaries as part of a MapComponent, each recording a count of a certain timer for each pawn (for example, one is a dictionary where each Pawn has an int counting up to a certain value). I need to save these so they aren't reset to new each time, as they currently are. How do I add them to the player's save file?
Title: Re: How to save a variable?
Post by: krafs on January 16, 2020, 02:00:54 PM
Have a look at this guide. It covers saving in Rimworld.

https://spdskatr.github.io/RWModdingResources/saving-guide.html (https://spdskatr.github.io/RWModdingResources/saving-guide.html)

Basically, you implement IExposable on a class, and do your saves with different Scribe-methods within the ExposeData-method. It's all in the link.
As it so happens, MapComponent already implements IExposable, so you can go ahead and override it.
Do note that MapComponents are bound to a particular map, and if you e.g. abandon a map you'll lose the data. If that's fine, then go ahead.
GameComponent can also save data, but persists across all maps. It's bound to a game/save.
Title: Re: How to save a variable?
Post by: battlemage64 on February 15, 2020, 12:44:41 PM
Thank you!!!!

(didn't see this for a month but it works now)