Hi there! You are currently browsing as a guest. Why not create an account? Then you get less ads, can thank creators, post feedback, keep a list of your favourites, and more!
Test Subject
Original Poster
#1 Old 30th May 2017 at 7:54 PM
Default How to store informations in saved game
I'm trying to make my mod store an int variable, one per sim in the game, to know if they are on the good or evil side of their faith. It's a bit like the sexual orientation variable that exists in the original game, except the gender preference is a private int variable inside the "Sim" class. Anyway.
I know variable storing is possible, cause mods like twallan's use it to store mod options parameters.
Now, my idea is to store just one big dictionnary-type variable, which would relate the said faith variable to, say, each Sim name (or any unique property of the Sim).
I just can't figure out how to make the game (or the mod) store the variable. Any ideas ?
Advertisement
Field Researcher
#2 Old 10th Jun 2017 at 8:33 PM
Quote: Originally posted by Armise
I'm trying to make my mod store an int variable, one per sim in the game, to know if they are on the good or evil side of their faith. It's a bit like the sexual orientation variable that exists in the original game, except the gender preference is a private int variable inside the "Sim" class. Anyway.
I know variable storing is possible, cause mods like twallan's use it to store mod options parameters.
Now, my idea is to store just one big dictionnary-type variable, which would relate the said faith variable to, say, each Sim name (or any unique property of the Sim).
I just can't figure out how to make the game (or the mod) store the variable. Any ideas ?


It needs to be persistable.

You need to add [assembly: PersistableStatic] into you AssemblyInfo.cs file. I also throw [Assembly: Tunable] in there at the same time.

Then, when you declare your Dictionary, put [Persistable] above it. Here's a bunch of examples from my Horse Boarding mod:

Code:
        [PersistableStatic]
        public static bool BoardingActivated;
        [PersistableStatic]
        public static List<ulong> BoardingStatus;

        [PersistableStatic]
        public static Dictionary<ulong, float> BoardingCost;

        [PersistableStatic]
        public static Dictionary<SimDescription, ulong> BoardedHorses;

        [PersistableStatic]
        public static float BoardMultipler;



You'd probably want to have a dictionary like

Code:
[PersistableStatic]
public static Dictionary<SimDescription, int> FaithValue;


Then store the int with that Sim's SimDescription. IDK what else you are doing but you could have it check the Dictionary when you load up a game / household and change that value if necessary.
Test Subject
Original Poster
#3 Old 24th Dec 2017 at 10:01 PM
Quote: Originally posted by pjsutton
You'd probably want to have a dictionary like

Code:
[PersistableStatic]
public static Dictionary<SimDescription, int> FaithValue;


Then store the int with that Sim's SimDescription. IDK what else you are doing but you could have it check the Dictionary when you load up a game / household and change that value if necessary.


Thank you !
I guess to add a sim in the dict with 0 as a level of faith, i would do :
Code:
foreach (Sim sim in Sims3.Gameplay.Queries.GetObjects<Sim>())
{
      if (sim != null)
     {
          FaithValue.Add(sim.SimDescription, 0)
     }
}

And the faith value of a sim is :
Code:
FaithValue[sim.SimDescription]


But how do I check wether or not there already is an instance of this dictionnary already existing in the game ?
My namespace is (currently) Armise and my class is AngelsAndDemons (name of my mod), do I call the dictionary Armise.AngelsAndDemons.FaithValue ? this.FaithValue ?
Back to top