Home | Download | Discussion | Help | Site Map | New Posts | Sign in

Latest Site News

Nysha's New Creators for July - posted on 1st Aug 2018 at 9:00 AM
Replies: 2 (Who?), Viewed: 3125 times.
Instructor
Original Poster
#1 Old 10th May 2018 at 11:14 PM
Default 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
Instructor
Original Poster
#2 Old 11th May 2018 at 12:47 PM
I got the answer. Chain reaction at Nraas helped me out.
Lab Assistant
#3 Old 11th May 2018 at 4:22 PM
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
Back to top