Replies: 7 (Who?), Viewed: 487 times.
#1
28th Jul 2020 at 1:27 PM
Last edited by Lyralei : 28th Jul 2020 at 3:53 PM.

Posts: 3,093
Thanks: 3434 in 21 Posts

This is indeed a lot for one question tbh :p but one is more or less a "am I doing this right" and the other is just really confusing me. Again, it's about data getting resetted on reloading the game.
1. Persistable Data
Currently I'm trying to keep data stored during gameplay in a dictionary. The dictionary holds both a SimDescription and a Resource key, so that I can figure out who already discovered what objects. Now, using the example given in this thread I've come up with this:
Code:
And in my 'instantiator' class I've done the following: [Persistable] public class PersistedData { [Persistable] public Dictionary<SimDescription, ResourceKey> mDiscoveredObjects; public PersistedData() { if(mDiscoveredObjects == null) { mDiscoveredObjects = new Dictionary<SimDescription, ResourceKey>(); } } public void Cleanup() { mDiscoveredObjects = null; } }
Code:
I *think* either I'm misunderstanding what the persistable data does or it being the Cleanup that sets it back to null after the player saves and quits the game. But I'm not entirely sure. [PersistableStatic] protected static PersistedData sSettings; public static PersistedData retrieveData { get { if (GlobalOptionsSewingTable.sSettings == null) { GlobalOptionsSewingTable.sSettings = new PersistedData(); } return GlobalOptionsSewingTable.sSettings; } }
Now I will say, I do re-instantiate it in the following way when calling the dictionary var, which feels odd to me, hence why I'm mentioning it :p This is just an example of one of the ways I do it (keep in mind that they're inside static functions):
Code:
(actorDesc being obviously the actor's SimDescription).PersistedData pd = new PersistedData(); if(pd.whoIsInPatternClub.ContainsKey(ActorDesc)) { pd.whoIsInPatternClub.Remove(ActorDesc); }
tl;dr: How do I keep the dictionary data that has been obtained, even when the game has been saved, quit and later rebooted again?
2. Alarms
My second problem is the alarms I set up on the mailboxes. This alarm basically gives a pattern to the mailbox and the mailperson will deliver said pattern. Now, again (lol), that also gets reset on restarting the game. And I just can't seem to see why, since I did actually look really closely to what EA did. Here's what I have:
Code:
I also tried doing this:public static void OnWorldLoadFinished(object sender, EventArgs e) { JoinPatternClub club = new JoinPatternClub(); // JoinPatternClub is a computer interaction. mPatternClubAlarm = AlarmManager.Global.AddAlarmDay(1f, DaysOfTheWeek.Thursday, club.SendPatterns, "Mailbox: Pattern club", AlarmType.NeverPersisted, null); } public static void OnWorldQuit(object sender, EventArgs e) { AlarmManager.Global.RemoveAlarm(mPatternClubAlarm); mPatternClubAlarm = AlarmHandle.kInvalidHandle; }
Code:
But alas, it no work :pstatic GlobalOptionsSewingTable() // Is the instantiator { LoadSaveManager.ObjectGroupsPostLoad += new ObjectGroupsPostLoadHandler(GlobalOptionsSewingTable.OnPostWorldLoad); } public static void OnPostWorldLoad() { JoinPatternClub club = new JoinPatternClub(); GlobalOptionsSewingTable.mPatternClubAlarm = AlarmManager.Global.AddAlarmDay(1f, DaysOfTheWeek.All, club.SendPatterns, "Mailbox: Pattern club", AlarmType.NeverPersisted, null); }
Again, sorry for throwing so much at you guys! Hopefully it's a bit clear, but do let me know if it isn't. The current Sewing table that has been uploaded doesn't have this code, so that's not really a great reference to use if you do

Advertisement
#2
28th Jul 2020 at 7:43 PM

Posts: 3,093
Thanks: 3434 in 21 Posts
Regarding the first issue, turns out that I hadn't put the following in my Assembly info:
Still trying to figure out the alarm issue though. I'm almost wondering if I should change 'AlarmType.NeverPersisted' to 'AlwaysPersisted'
Code:
Big thanks to @battery ! [assembly: PersistableStatic]
Still trying to figure out the alarm issue though. I'm almost wondering if I should change 'AlarmType.NeverPersisted' to 'AlwaysPersisted'
#3
29th Jul 2020 at 10:56 AM

Posts: 3,093
Thanks: 3434 in 21 Posts
Quote:
Originally Posted by Lyralei
Regarding the first issue, turns out that I hadn't put the following in my Assembly info:
Code:
Big thanks to @battery ! [assembly: PersistableStatic] Still trying to figure out the alarm issue though. I'm almost wondering if I should change 'AlarmType.NeverPersisted' to 'AlwaysPersisted' |
#4
29th Jul 2020 at 4:43 PM

I'm still pretty green so who knows if I understand anything, but does the OnWorldQuit method not guarantee that mPatternClubAlarm will always be removed and need to be reset every time you leave and reload the world, no matter how that alarm is made? If not I've been misunderstanding how those work all this time and need to fix something I'm working on
Also I'm curious what the difference between alarm types is, I've always just sort of guessed at that. I'm going to test and see if my pregnancy moodlets mod also has this problem with alarms resetting, since I use a NeverPersisted alarm for that too but don't remove it on world quit. Hey, I wonder if you could make a dictionary of alarm handles...

Also I'm curious what the difference between alarm types is, I've always just sort of guessed at that. I'm going to test and see if my pregnancy moodlets mod also has this problem with alarms resetting, since I use a NeverPersisted alarm for that too but don't remove it on world quit. Hey, I wonder if you could make a dictionary of alarm handles...
#5
29th Jul 2020 at 8:16 PM
Last edited by Battery : 29th Jul 2020 at 8:44 PM.

Posts: 385
Thanks: 825 in 5 Posts
So i overread your Alarm question last time.
Are you sure your club.SendPatterns is able to be called since i dont see it beeing persistable or static.
E: Make sure your callback method exists !
A bit from my Abductor mod (slightly altered)
Works for me (Timer is a method thats either static or part of ther persistable class instance)
Are you sure your club.SendPatterns is able to be called since i dont see it beeing persistable or static.
E: Make sure your callback method exists !
A bit from my Abductor mod (slightly altered)
Code:
objektalarmhandler = AlarmManager.Global.AddAlarmDay(8,DaysOfTheWeek.All, Timer, "alarm", AlarmType.AlwaysPersisted,null);
Works for me (Timer is a method thats either static or part of ther persistable class instance)
#6
30th Jul 2020 at 2:42 AM
Last edited by gamefreak130 : 30th Jul 2020 at 3:00 AM.

Posts: 268
Thanks: 2642 in 18 Posts
Quote:
Originally Posted by lizcandor
I'm still pretty green so who knows if I understand anything, but does the OnWorldQuit method not guarantee that mPatternClubAlarm will always be removed and need to be reset every time you leave and reload the world, no matter how that alarm is made? If not I've been misunderstanding how those work all this time and need to fix something I'm working on
![]() |
That's correct -- in fact, explicitly clearing the alarm on WorldQuit is unnecessary, since the alarm is NeverPersisted and the game purges the global AlarmManager automatically. That should be okay here, though, as it will be re-applied with (presumably) the exact same functionality on WorldLoadFinished.
@Lyralei If possible, I would try making your callback a static function. That's what EA does for the book club alarms, after all.
Quote:
Originally Posted by lizcandor
Also I'm curious what the difference between alarm types is, I've always just sort of guessed at that. I'm going to test and see if my pregnancy moodlets mod also has this problem with alarms resetting, since I use a NeverPersisted alarm for that too but don't remove it on world quit. Hey, I wonder if you could make a dictionary of alarm handles...
|
Here's a comparison table for reference:
Alarm Type | Preserved when owner object is reset? | Preserved on saving and quitting? |
---|---|---|
AlwaysPersisted | Yes | Yes |
DeleteOnReset | No | Yes |
NeverPersisted | No | No |
Owner objects are the GameObjects passed as the last argument to the alarm add methods. Typically they are null for global alarms, in which case DeleteOnReset and AlwaysPersisted are functionally equivalent. Global alarms almost never need to be persisted, though -- just readded on WorldLoadFinished. That way, there's a little bit less to save and load in an already-bloated game.
"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
If you enjoy the mods I put out, consider supporting me on patreon: www.patreon.com/Gamefreak130
#7
31st Jul 2020 at 4:59 PM

Posts: 3,093
Thanks: 3434 in 21 Posts
This is super helpful! Thank you @gamefreak130
The source code, I will say, was pretty confusing to figure out what it does, so thanks again for making such a great scheme there!
Not a bad idea. Would need to do some code shifting and what-not (Since I somehow thought it's a good idea to put the original function in the interaction, which you can't really make any static functions inside of). But I think indeed this will probably fix it. Thanks for your help again! You guys are great

Quote:
Originally Posted by Battery
Are you sure your club.SendPatterns is able to be called since i dont see it beeing persistable or static.
|
Quote:
Originally Posted by gamefreak130
@Lyralei If possible, I would try making your callback a static function. That's what EA does for the book club alarms, after all.
|

#8
1st Aug 2020 at 12:09 AM

That table is exactly what I needed to know! Thank you!
Who Posted
|