- Site Map >
- Modding and Creation >
- Sims 3 Creation >
- Modding Discussion >
- Failing to add a Sim's SimDescriptionID to a dictionary.
- Site Map >
- Modding and Creation >
- Sims 3 Creation >
- Modding Discussion >
- Failing to add a Sim's SimDescriptionID to a dictionary.
Replies: 7 (Who?), Viewed: 437 times.
#1
19th Mar 2023 at 5:21 AM
Posts: 268
Thanks: 1168 in 17 Posts
Failing to add a Sim's SimDescriptionID to a dictionary.
Regrettably, I am having a hard time working with a dictionary. I will do my best to explain. So I have an alarm that triggers a function. When the alarm is triggered, it is suppose to check which sims are in the dictionary. If the sims are in the dictionary, then the function will trigger for those sims. Otherwise if the sim is not on the dictionary it will not trigger. I will now share my code and explain to the best of my ability what I was trying to do.
//In the InRabbitHole function, the Sim's SimDescriptionID should be added to the Dictionary via the anInstanceofMyClass.AddArmsDeal(Actor.SimDescription.SimDescriptionId, true); function anytime a sim performs the custom rabbithole interaction.
Code:
//This is my AddArmsDeal function that the code above references. Which I believe it should add the SimDescriptionID of the sim to the Dictionary.
public override bool InRabbitHole() { StartStages(); BeginCommodityUpdates(); bool flag = DoLoop(ExitReason.Default | ExitReason.Replan); EndCommodityUpdates(flag); var anInstanceofMyClass = new SavedData(); if (flag) { anInstanceofMyClass.AddArmsDeal(Actor.SimDescription.SimDescriptionId, true); Helpers.ArmsDealPaymentAlarm(Actor); Helpers.ArmsDealReceivinAlarm(Actor); } return flag; }
Code:
//Here are my two alarms that are also added when the sim performs the custom RabitHole interaction.
public void AddArmsDeal(ulong SimID, bool ArmsDealSet) { ArmsDeal[SimID] = ArmsDealSet; }
Code:
//When the Alarms trigger, they both check whether each individual sim in a active household is in the dictionary. Before, I had it as a condition where the code would only run if the sim was in the dictionary, but then the code was not triggering. So, I changed it to a function that would check whether any of the sims was in the dictionary.
public static void ArmsDealPaymentAlarm(Sim sim) { AlarmManager.Global.AddAlarmDay(12f, DaysOfTheWeek.Sunday, AlarmCallBack ,"ArmsDeal Alarm", AlarmType.AlwaysPersisted, null); } public static void ArmsDealReceivinAlarm(Sim sim) { AlarmManager.Global.AddAlarmDay(12f, DaysOfTheWeek.All, AlarmCallBack2, "ArmsDealReceiving Alarm", AlarmType.AlwaysPersisted, null); }
Code:
//This is the code that checks whether the Sim's SimDescriptionID is in the dictionary. If it is then it should shoot a notification saying Key Found. Otherwise it will return Key Not Found.
public static void AlarmCallBack() { var anInstanceofMyClass = new SavedData(); foreach (var CurrentSim in Sim.ActiveActor.Household.Sims) { { CurrentSim.ModifyFunds(-2500); anInstanceofMyClass.HasArmsDeal(CurrentSim.SimDescription, true); } } } public static void AlarmCallBack2() { var anInstanceofMyClass = new SavedData(); foreach (var CurrentSim in Sim.ActiveActor.Household.Sims) { { LoopForGunItems2(CurrentSim); anInstanceofMyClass.HasArmsDeal(CurrentSim.SimDescription, true); } } }
Code:
However, unfortunately, it seems like the sim's SimDescriptionID is not being added to the dictionary, because regarldess of whether the sim performs the custom Rabbithole Interaction. The result has always been Key Not Found. At this moment I am honestly at a loss. It's possible that I either performed a logical error somewhere that I have yet to find or I misinterpreted what a line of code actually does. Any help would be appreciated. Thanks.
public bool HasArmsDeal(ulong SimID, bool ArmsDealSet) { if (ArmsDeal.ContainsKey(SimID) && ArmsDeal[SimID] == ArmsDealSet) { StyledNotification.Show(new StyledNotification.Format("Key Found", StyledNotification.NotificationStyle.kDebugAlert)); return true; } else { StyledNotification.Show(new StyledNotification.Format("Key Not Found", StyledNotification.NotificationStyle.kDebugAlert)); return false; } } public bool HasArmsDeal(SimDescription SD1, bool ArmsDealSet) { return HasArmsDeal(SD1.SimDescriptionId, true); } }
Advertisement
Field Researcher
#2
19th Mar 2023 at 11:30 AM
Posts: 224
Thanks: 997 in 7 Posts
I am going to link you the dictionary description I sent you on Discord again. Read it!
Then you will se that you are not using the code to add a new pair to the dictionary but the code to use if you update an already existing entry.
https://www.tutorialsteacher.com/cs...harp-dictionary
Then you will se that you are not using the code to add a new pair to the dictionary but the code to use if you update an already existing entry.
https://www.tutorialsteacher.com/cs...harp-dictionary
#3
19th Mar 2023 at 9:22 PM
Posts: 268
Thanks: 1168 in 17 Posts
Quote: Originally posted by KittyTheSnowcat
I am going to link you the dictionary description I sent you on Discord again. Read it! Then you will se that you are not using the code to add a new pair to the dictionary but the code to use if you update an already existing entry. https://www.tutorialsteacher.com/cs...harp-dictionary |
Code:
However, the end result is Key Not found as well. Did I miss something? I believe this is what you were referring to. I'll come back after a break and reread the link to see if I did indeed miss something. Thanks for your input
public void AddArmsDeal(ulong SimID, bool ArmsDealSet) { ArmsDeal.Add(SimID, ArmsDealSet); }
Test Subject
#4
21st Mar 2023 at 1:41 PM
Last edited by BrianMoore : 27th Mar 2023 at 8:15 AM.
Posts: 1
Thanks for the link, you made my day. If your children are struggling in maths and you don't know what to do, I recommend this website: https://parccgames.com/ here you may find a variety of games that can assist your youngsters develop an interest in maths.
Field Researcher
#5
21st Mar 2023 at 6:30 PM
Posts: 224
Thanks: 997 in 7 Posts
You are saving the dictionary in a SavedData, but you did not add your definition of that. Also you make a new one everytime you want to add it. Does it contain a static dictionary? Could you share the code?
#6
22nd Mar 2023 at 12:59 AM
Posts: 268
Thanks: 1168 in 17 Posts
Quote: Originally posted by KittyTheSnowcat
You are saving the dictionary in a SavedData, but you did not add your definition of that. Also you make a new one everytime you want to add it. Does it contain a static dictionary? Could you share the code? |
Hello @KittyTheSnowcat, here is my code. The dictionary should be on MonocoDoll.ArmsDealingMod.Common.SavedData. And then the MonocoDoll.ArmsDealingMod.RabbitHoles.PoliceStationDailySupplyForGunsInteraction.InRabbitHole is the method which tries to add the key to the sim whenever they finish the rabbithole interaction. Please let me know if you need anything else. Again thanks.
Attached files:
MonocoDoll ArmsDealingProject.zip (7.2 KB, 4 downloads) |
Field Researcher
#7
22nd Mar 2023 at 6:57 PM
Posts: 224
Thanks: 997 in 7 Posts
Everytime you save to that dictionary you make a new SavedData with a new dictionary. And then when you want to read it, you make a new SavedData with a new empty dictionary and read from that.
Make your SavedData class static. And then instead of creating a new instance each time, call the one and only Saved Data with its Dictionary inside.
public static class SavedData
{
[Persistable]
public Dictionary<ulong, bool> ArmsDeal;
public void AddArmsDeal(ulong SimID, bool ArmsDealSet)
{
if (ArmsDeal == null)
{
ArmsDeal = new Dictionary<ulong, bool>();
}
if (!ArmsDeal.ContainsKey(SimID)){
ArmsDeal.Add(SimID, ArmsDealSet);
}
else {
ArmsDeal[SimID] = ArmsDealSet;
}
Make your SavedData class static. And then instead of creating a new instance each time, call the one and only Saved Data with its Dictionary inside.
public static class SavedData
{
[Persistable]
public Dictionary<ulong, bool> ArmsDeal;
public void AddArmsDeal(ulong SimID, bool ArmsDealSet)
{
if (ArmsDeal == null)
{
ArmsDeal = new Dictionary<ulong, bool>();
}
if (!ArmsDeal.ContainsKey(SimID)){
ArmsDeal.Add(SimID, ArmsDealSet);
}
else {
ArmsDeal[SimID] = ArmsDealSet;
}
#8
23rd Mar 2023 at 3:29 AM
Posts: 268
Thanks: 1168 in 17 Posts
Thank you so much! Making the SavedData static made it work. It gave me errors on other functions of the code. However, after researching the errors and making the adjustments in order to fix the errors. It all made it work in the end. Again thank you so much. I'm not the best at particularly anything here, but if there is anything I can do to repay you. Then please let me know. Have a great rest of your day.
Who Posted
|