Ludeon Forums

Ludeon Forums

  • August 03, 2020, 04:32:14 PM
  • Welcome, Guest
Please login or register.

Login with username, password and session length
Advanced search  

Author Topic: How to save a variable?  (Read 374 times)

battlemage64

  • Drifter
  • **
  • Posts: 99
  • Reward: plasteel animal sleeping box (legendary)
    • View Profile
How to save a variable?
« 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?
Logged
I DON'T CARE IF YOU'RE DYING OF FROSTBITE! MINE THE DAMN BLOCK SO I CAN BUILD YOU A DAMN HEATER! STOP WALKING AWAY! NO! NO! ARRGH!

*switches to dev mode, kills pawn in big explosion*

krafs

  • Drifter
  • **
  • Posts: 42
  • Maker
    • View Profile
Re: How to save a variable?
« Reply #1 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

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.
Logged

battlemage64

  • Drifter
  • **
  • Posts: 99
  • Reward: plasteel animal sleeping box (legendary)
    • View Profile
Re: How to save a variable?
« Reply #2 on: February 15, 2020, 12:44:41 PM »

Thank you!!!!

 (didn't see this for a month but it works now)
Logged
I DON'T CARE IF YOU'RE DYING OF FROSTBITE! MINE THE DAMN BLOCK SO I CAN BUILD YOU A DAMN HEATER! STOP WALKING AWAY! NO! NO! ARRGH!

*switches to dev mode, kills pawn in big explosion*