How to save a variable?

Started by battlemage64, January 15, 2020, 07:32:07 PM

Previous topic - Next topic

battlemage64

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?
I love to mod and boy am I bad at it

krafs

Have a look at this guide. It covers saving in Rimworld.

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.

battlemage64

Thank you!!!!

(didn't see this for a month but it works now)
I love to mod and boy am I bad at it