#1
28th Jul 2020 at 12:27 PM
Last edited by Lyralei : 28th Jul 2020 at
2:53 PM.
Posts: 3,860
Thanks: 8561 in 67 Posts
28 Achievements
Alarms and persisted data
Hi everyone!
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:
[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;
}
}
And in my 'instantiator' class I've done the following:
Code:
[PersistableStatic]
protected static PersistedData sSettings;
public static PersistedData retrieveData
{
get
{
if (GlobalOptionsSewingTable.sSettings == null)
{
GlobalOptionsSewingTable.sSettings = new PersistedData();
}
return GlobalOptionsSewingTable.sSettings;
}
}
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.
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:
PersistedData pd = new PersistedData();
if(pd.whoIsInPatternClub.ContainsKey(ActorDesc))
{
pd.whoIsInPatternClub.Remove(ActorDesc);
}
(actorDesc being obviously the actor's SimDescription).
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:
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;
}
I also tried doing this:
Code:
static 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);
}
But alas, it no work :p
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
.