- Site Map >
- Modding and Creation >
- Sims 3 Creation >
- Modding Discussion >
- Help with data Clean up
- Site Map >
- Modding and Creation >
- Sims 3 Creation >
- Modding Discussion >
- Help with data Clean up
Replies: 2 (Who?), Viewed: 3835 times.
#1
10th May 2018 at 11:14 PM
Posts: 1,500
Thanks: 4283 in 41 Posts
Help with data Clean up
So I've been working with [Persistable] and I want to make sure there's no bleeding between saves. So I need a little help with that as I've not worked with something like this before.This is the class that contains the values that need to be saved.
Code:
[Persistable] public class SavedData { [Persistable] public static Dictionary<ulong, ulong> SlaveMaster = new Dictionary<ulong, ulong>(); [Persistable] public Dictionary<ulong, ulong> SlaveMasterRecord = new Dictionary<ulong, ulong>(); public SavedData() //Important !!! even if you dont use the Constructor You have to implement it if you want it to survive loading a game { } public static void AddSlaveMasterRelation(ulong SlaveID, ulong MasterID) { if (CanRunInteraction(SlaveID, MasterID)) { if (!SlaveMaster.ContainsKey(SlaveID)) { SlaveMaster.Add(SlaveID, MasterID); } } } public static void RemoveSlaveMasterRelation(ulong SlaveID) { SlaveMaster.Remove(SlaveID); } public static bool CanRunInteraction(ulong SlaveID, ulong MasterID) { if (SlaveMaster.ContainsKey(SlaveID)) { if (SlaveMaster[SlaveID] != MasterID) { return false; } } return true; } public static bool ValidCommand(ulong SlaveID, ulong MasterID) { ulong found; if (SlaveMaster.TryGetValue(SlaveID, out found) && found == MasterID) { return true; // key/value pair exists } return false; } public void Cleanup() { SlaveMasterRecord = SlaveMaster; SlaveMaster.Clear(); SlaveMaster = null; } public void OnLoad() { SlaveMaster = SlaveMasterRecord; } }
Should I change OnLoad() and Cleanup() to static as well?
Now this is the OnWorldLoad
Code:
public static void OnWorldLoadFinishedHandler(object sender, System.EventArgs e) { try { ReplaceBuffHeatingUp(); ReplaceBuffTooMuchSun(); foreach (Sim sim in Sims3.Gameplay.Queries.GetObjects<Sim>()) { if (sim != null) { AddInteractions(sim); AddCompelInteractions(sim); AddCommandInteractions(sim); sSimInstantiatedListener = EventTracker.AddListener (EventTypeId.kSimInstantiated, new ProcessEventDelegate(OnSimInstantiated)); sSimAgedUpListener = EventTracker.AddListener (EventTypeId.kSimAgeTransition, new ProcessEventDelegate(OnSimAgeUp)); } } SavedData saveddata = new SavedData(); saveddata.OnLoad(); } catch (Exception exception) { Exception(exception); } }
And this is the OnWorldQuit
Code:
public static void OnQuit(object sender, System.EventArgs e) { //SavedData Sdata = new SavedData(); SavedData Sdata = new SavedData(); Sdata.Cleanup(); }
I'm pretty sure there is something wrong here. First of all there are two different objects of SavedData in OnWorldLoad and OnQuit and that's not going to work.
So what to do? What's the best way to handle this?
Advertisement
#2
11th May 2018 at 12:47 PM
Posts: 1,500
Thanks: 4283 in 41 Posts
I got the answer. Chain reaction at Nraas helped me out.
Space Pony
#3
11th May 2018 at 4:22 PM
Posts: 433
Thanks: 792 in 6 Posts
Quote: Originally posted by skydome
I got the answer. Chain reaction at Nraas helped me out. |
Aww and i didnt even get the chance to answer
But to give this post some content your method ValidCommand does the same thing as CanRunInteraction so you might want to retire one of the methods
Who Posted
|