Wondering if anyone here could help explain this for me.
It was pointed out to me that one of my script mods wasn't cooperating with another script mod by SimsMx. Upon investigation, it seems that when both both mods are installed, the OnObjectPlacedInLotEventHandle in my mod is not run. Peeking into SimsMx's mod, he had this in his OnWorldLoadFinished method:
World.sOnObjectPlacedInLotEventHandler = new EventHandler(Main.EventDelegateFunctions.OnObjectPlacedInLot);
So I guessed that meant when his mod is loaded, everything that was in World.sOnObjectPlacedInLotEventHandler before is effectly wiped out by this line. Funny thing is, I have several mods that use a OnObjectPlacedInLotEventHandle to add interactions to objects when they are bought and placed on lots, but only the one in this one mod I have seems affected by this (its supposed to add new interactions to coffee machines, which works as expected when SimsMX's mod isn't there but not if it is) whereas the method in all my other mods work correctly. I've tried loading my mod in a higher priority folder, and even tried the reverse and put SimsMX's at a higher priority, but the issue still persists either way.
It's kind of ironic really since I only learnt about this method of adding interactions to newly bought items from an answer to a thread left by SimsMX himself.
Creating an NRaas project Script mod conundrum
- Chain_Reaction
- Site Admin
- Reactions:
- Posts: 7596
- Joined: December 30th, 2011, 6:00 pm
- Contact:
- icarus_allsorts
- Reactions:
- Posts: 213
- Joined: March 8th, 2012, 6:00 pm
The first one is just a new instance of the World.sOnObjectPlacedInLotEventHandler delegate, which he will probably add to the Event later on, while the second one is directly adding a new instance of the delegate to the Event.
Events can't be wiped out, that's what they're made for, they only allow adding and removing delegates explicitly, no accidents can occur there, as Chain already noted
Events can't be wiped out, that's what they're made for, they only allow adding and removing delegates explicitly, no accidents can occur there, as Chain already noted
- icarus_allsorts
- Reactions:
- Posts: 213
- Joined: March 8th, 2012, 6:00 pm
Okay, thanks for clearing that up guys. I've yet to encounter in his mod where the new instance of the World.sOnObjectPlacedInLotEventHandler delegate is eventually added though and the methods we use pertain to totally different objects so am absolutely baffled by this one. It could be the issue isn't even here since none of the World.sOnObjectPlacedInLotEventHandler delegates from my other mods seem affected.
Just to be clear : Events cannot be wiped out except in this case where having unprotected DLLs made it possible. So, yes, you were right, I didn't notice before cos I thought EA's had its own delegate, but it doesn't, which means his mod is literally clearing all the delegate functions added prior to his OnWorldLoadFinished function. As I said in the previous post, use an alarm to add yours and there will be no more problems, since you don't need it added before then anyway
- icarus_allsorts
- Reactions:
- Posts: 213
- Joined: March 8th, 2012, 6:00 pm
NRaas mods have that event hooked delayed, that's why. Again, use an alarm and then add the delegate function :
<!-- ws:start:WikiTextCodeRule:0:
<pre class="text">static void OnWorldLoadFinished(object sender, EventArgs e)<br/>{<br/> AlarmManager.Global.AddAlarm(1f, TimeUnit.Seconds, new AlarmTimerCallback(MyClass.OnAlarm), "Add OnObjectPlacedInLot", AlarmType.NeverPersisted, null);<br/>}<br/><br/>static void OnAlarm()<br/>{<br/> World.OnObjectPlacedInLotEventHandler += new EventHandler(MyClass.OnObjectPlacedInLot);<br/>}<br/><br/>static void OnObjectPlacedInLot(object sender, EventArgs eventArgs)<br/>{<br/> //add interactions<br/>}</pre>
-->
<style type="text/css"><!--
/**
* GeSHi (C) 2004 - 2007 Nigel McNie, 2007 - 2008 Benny Baumann
* (http://qbnz.com/highlighter/ and http://geshi.org/)
*/
.text {font-family:monospace;}
.text .imp {font-weight: bold; color: red;}
.text span.xtra { display:block; }
-->
</style><pre class="text">static void OnWorldLoadFinished(object sender, EventArgs e)
{
AlarmManager.Global.AddAlarm(1f, TimeUnit.Seconds, new AlarmTimerCallback(MyClass.OnAlarm), "Add OnObjectPlacedInLot", AlarmType.NeverPersisted, null);
}
static void OnAlarm()
{
World.OnObjectPlacedInLotEventHandler += new EventHandler(MyClass.OnObjectPlacedInLot);
}
static void OnObjectPlacedInLot(object sender, EventArgs eventArgs)
{
//add interactions
}</pre>
<!-- ws:start:WikiTextCodeRule:0:
<pre class="text">static void OnWorldLoadFinished(object sender, EventArgs e)<br/>{<br/> AlarmManager.Global.AddAlarm(1f, TimeUnit.Seconds, new AlarmTimerCallback(MyClass.OnAlarm), "Add OnObjectPlacedInLot", AlarmType.NeverPersisted, null);<br/>}<br/><br/>static void OnAlarm()<br/>{<br/> World.OnObjectPlacedInLotEventHandler += new EventHandler(MyClass.OnObjectPlacedInLot);<br/>}<br/><br/>static void OnObjectPlacedInLot(object sender, EventArgs eventArgs)<br/>{<br/> //add interactions<br/>}</pre>
-->
<style type="text/css"><!--
/**
* GeSHi (C) 2004 - 2007 Nigel McNie, 2007 - 2008 Benny Baumann
* (http://qbnz.com/highlighter/ and http://geshi.org/)
*/
.text {font-family:monospace;}
.text .imp {font-weight: bold; color: red;}
.text span.xtra { display:block; }
-->
</style><pre class="text">static void OnWorldLoadFinished(object sender, EventArgs e)
{
AlarmManager.Global.AddAlarm(1f, TimeUnit.Seconds, new AlarmTimerCallback(MyClass.OnAlarm), "Add OnObjectPlacedInLot", AlarmType.NeverPersisted, null);
}
static void OnAlarm()
{
World.OnObjectPlacedInLotEventHandler += new EventHandler(MyClass.OnObjectPlacedInLot);
}
static void OnObjectPlacedInLot(object sender, EventArgs eventArgs)
{
//add interactions
}</pre>