Welcome to
Mod The Sims
Online: 1117
News:
Have an account? Sign in:
pass:
If you don't have an account, why not sign up now? It's free!
Other sites: SimsWiki
Reply  Replies: 11 (Who?), Viewed: 305 times.
Search this Thread
Old 29th Nov 2020, 4:36 PM DefaultPersistable tuples not persisting #1
lizcandor
Original Poster

Lab Assistant

Join Date: Jan 2012
Posts: 140
Thanks: 308 in 2 Posts
5 Achievements

View My Journal


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.
Old 29th Nov 2020, 4:53 PM #2
Battery
Field Researcher

Join Date: Dec 2008
Posts: 385
Thanks: 825 in 5 Posts
8 Achievements


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 ?
Last edited by Battery : 29th Nov 2020 at 5:05 PM.
Old 29th Nov 2020, 5:09 PM #3
gamefreak130
Field Researcher

Join Date: Apr 2013
Posts: 268
Thanks: 2643 in 18 Posts
17 Achievements


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
Old 29th Nov 2020, 5:09 PM #4
lizcandor
Original Poster

Lab Assistant

Join Date: Jan 2012
Posts: 140
Thanks: 308 in 2 Posts
5 Achievements

View My Journal


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!
Old 29th Nov 2020, 5:12 PM #5
Battery
Field Researcher

Join Date: Dec 2008
Posts: 385
Thanks: 825 in 5 Posts
8 Achievements


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 ?
Old 29th Nov 2020, 5:19 PM #6
gamefreak130
Field Researcher

Join Date: Apr 2013
Posts: 268
Thanks: 2643 in 18 Posts
17 Achievements


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
Old 29th Nov 2020, 5:38 PM #7
lizcandor
Original Poster

Lab Assistant

Join Date: Jan 2012
Posts: 140
Thanks: 308 in 2 Posts
5 Achievements

View My Journal


@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
Old 29th Nov 2020, 7:24 PM #8
echoweaver
Instructor

Join Date: Jun 2011
Posts: 507
Thanks: 405 in 13 Posts
6 Achievements


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
Old 29th Nov 2020, 9:52 PM #9
lizcandor
Original Poster

Lab Assistant

Join Date: Jan 2012
Posts: 140
Thanks: 308 in 2 Posts
5 Achievements

View My Journal


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.
Old 30th Nov 2020, 6:14 AM #10
echoweaver
Instructor

Join Date: Jun 2011
Posts: 507
Thanks: 405 in 13 Posts
6 Achievements


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
Old 30th Nov 2020, 3:09 PM #11
Lyralei
Virtual gardener



Join Date: Dec 2013
Posts: 3,093
Thanks: 3434 in 21 Posts
24 Achievements


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
Old 30th Nov 2020, 5:25 PM #12
echoweaver
Instructor

Join Date: Jun 2011
Posts: 507
Thanks: 405 in 13 Posts
6 Achievements


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
Reply


Section jump:


Powered by MariaDB Some icons by http://dryicons.com.