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!
Field Researcher
Original Poster
#1 Old 29th Nov 2020 at 3:36 PM
Default Persistable tuples not persisting
I think the issue here must be with my use of tuples in particular, because all the persistable static variables I create in this class except for the dictionaries of tuples (sFosterHomes and FosterHomes) are fine.

I'm defining them like this:
Code:
[PersistableStatic]
public static Dictionary<ulong, Tuple> sFosterHomes;

public static Dictionary<ulong, Tuple> FosterHomes
{
    get
    {
         if (sFosterHomes == null)
         {
               sFosterHomes = new Dictionary<ulong, Tuple>();
         }
         return sFosterHomes;
    }
    set => sFosterHomes = value;
}
And setting them like this:
Code:
sFosterHomes.Add(simHouseholdId, new Tuple(FosterParents[simDescriptionId] as object, 0 as object))
With FosterParents being a persistable static dictionary of ulong keys and int values. They seem to work fine during a save (I'm able to get the parameters of the tuple for a specific household without any apparent problem), and only have problems when reloading.
Advertisement
Space Pony
#2 Old 29th Nov 2020 at 3:53 PM Last edited by Battery : 29th Nov 2020 at 4:05 PM.
Hmm this might be a silly uestion but did you add the Persistable static to your assembly ?

and are you sure you have to cast these types to object ?

also whats FosterParents ?
Space Pony
#3 Old 29th Nov 2020 at 4:09 PM
I'm assuming you're talking about Sims3.UI.Tuple? And FosterParents is persisting as expected, right? Those tuple objects are not themselves persistable, even if you put persistable objects in them, so you might need to create your own persistable tuple, as I did here in Job Overhaul:

Code:
namespace Gamefreak130.JobOverhaulSpace.Helpers 
{     
    [Persistable]     
    public class OccupationEntryTuple     
    {         
        public Occupation OccupationEntry { get; set; }          
        public CareerLocation CareerLocation { get; set; }          
        public OccupationEntryTuple()         
        {         
        }          
        public OccupationEntryTuple(Occupation entry, CareerLocation careerLocation)         
        {             
            OccupationEntry = entry;             
            CareerLocation = careerLocation;         
        }     
}


Note the empty constructor; persistable objects must have a constructor with no arguments in order for the game to capture them.

"The Internet is the first thing that humanity has built that humanity doesn't understand, the largest experiment in anarchy that we have ever had." - Eric Schmidt

If you enjoy the mods I put out, consider supporting me on patreon: www.patreon.com/Gamefreak130
Field Researcher
Original Poster
#4 Old 29th Nov 2020 at 4:09 PM
I have! I learned my lesson after the last time I spent like a day trying to understand why nothing was persisting

Hm, I think casting to object is necessary? That was my interpretation of the Tuple constructor in Sims3.UI:
Code:
public Tuple(object param1, object param2)
{
	mParam1 = param1;
	mParam2 = param2;
}
But I could be misunderstanding how the object type is supposed to be used. I also haven't been able to find many examples of Tuples being used like this, so I'm thinking about just going back to my array-using roots and storing the two ints I need in an array instead of a special structure like this.

EDIT: Oh hey simultaneous post! FosterParents is persisting, yeah - I'll give creating my own peristable tuple a try!
Space Pony
#5 Old 29th Nov 2020 at 4:12 PM
Hmm, you might need to make your own tuple class and make it persistable aswell

E: ok a bit to late can you post what the type of FosterParents[simDescriptionId] is ?
Space Pony
#6 Old 29th Nov 2020 at 4:19 PM
As an aside, I think Battery's right in that casting to object there wasn't explicitly necessary (and VS would have told you about it ). All objects in C# are inherently...well...objects, and the language allows derived types to be passed as their base type without any explicit casting.

"The Internet is the first thing that humanity has built that humanity doesn't understand, the largest experiment in anarchy that we have ever had." - Eric Schmidt

If you enjoy the mods I put out, consider supporting me on patreon: www.patreon.com/Gamefreak130
Field Researcher
Original Poster
#7 Old 29th Nov 2020 at 4:38 PM
@Battery FosterParents[simDescriptionId] is an int. Hey, is the reason the Tuple class in Sims3.UI isn't persistable that it doesn't have an empty constructor?

I've created my own persistable tuple and am testing it now - thanks, I'll update on how it works!

Edit: It worked! Thanks a lot, both of you! :D
Inventor
#8 Old 29th Nov 2020 at 6:24 PM
Ah! So you're the one working on the better foster system, lizcandor!

I'm trying to figure out how persistable data works for my custom skill, and I'm reading all over the forums on it. It's confusing :-/.

Echo Weaver's Simblr: http://echoweaver.tumblr.com/
A portrait in stubbornness - Playing the same legacy since 2009
Sample a Brave Legacy: http://sims3sample.illation.net
Field Researcher
Original Poster
#9 Old 29th Nov 2020 at 8:52 PM
I keep thinking I understand persistable data now and then realizing that I actually do not An especially sad example of a persistable data failure from earlier in this project: the class I was using to move groups of sims through the child protective services system wasn't persisting (which I now realize was because it hadn't had an empty constructor!) so if I quit and reloaded anytime between moving sims out of their original household for neglect and trying to return them, their case would get destroyed and they'd just be stranded wherever they were put.
Inventor
#10 Old 30th Nov 2020 at 5:14 AM
Argh. I've been trying to read through the forum to get a picture of how Persistable data works, but I still don't think I get it. I'm just doing custom skills, and I'm hoping that if I copy from the sewing table by rote, I'll get away with it....

Echo Weaver's Simblr: http://echoweaver.tumblr.com/
A portrait in stubbornness - Playing the same legacy since 2009
Sample a Brave Legacy: http://sims3sample.illation.net
Virtual gardener
staff: administrator
#11 Old 30th Nov 2020 at 2:09 PM
Quote: Originally posted by echoweaver
Argh. I've been trying to read through the forum to get a picture of how Persistable data works, but I still don't think I get it. I'm just doing custom skills, and I'm hoping that if I copy from the sewing table by rote, I'll get away with it....
@echoweaver , if you need some help, just let me know!  It indeed feels a bit as if you're coding a 'spiderweb' that links in different ways :p The one the sewing table has is linked to 50000 different things, so reading that can be a tough one! Just let me know if you have any questions, that's one of the reasons I put it on Github, so that people can understand how it was done
Inventor
#12 Old 30th Nov 2020 at 4:25 PM
Lyralei: I really appreciate you putting it on GitHub! I'm using it as a primary reference, and I have the beta package so that I can look at the resources. It's taught me a lot.

FWIW, I also have my stuff up in a GitHub repository: https://github.com/Echoweaver/Sims3Game

Now that I'm in the process of trying to break out the cat project into separate mods, the repository is likely to change quite a bit in the near future....

Echo Weaver's Simblr: http://echoweaver.tumblr.com/
A portrait in stubbornness - Playing the same legacy since 2009
Sample a Brave Legacy: http://sims3sample.illation.net
Back to top