Creating an NRaas project Script mod conundrum

Talk nerdy to us here.
icarus_allsorts
Reactions:
Posts: 213
Joined: March 8th, 2012, 6:00 pm

Script mod conundrum

Post by icarus_allsorts » April 19th, 2014, 5:11 pm

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.

User avatar
Chain_Reaction
Site Admin
Reactions:
Posts: 7596
Joined: December 30th, 2011, 6:00 pm
Answers: 81
Contact:

Post by Chain_Reaction » April 19th, 2014, 10:24 pm

Hmm. Not sure what is going on here. It's not wiping out events as sOnObjectPlacedInLotEventHandler is declared as an Event and those have wipe protection. The only thing I could think is his mod may be bouncing it in some way. Any script errors generated?

icarus_allsorts
Reactions:
Posts: 213
Joined: March 8th, 2012, 6:00 pm

Post by icarus_allsorts » April 20th, 2014, 5:03 am

No scripterrors. It was only my theory since none of the other features of either mod are affected and that the line in his mod reads
World.sOnObjectPlacedInLotEventHandler = new EventHandler(blah);
while mine is
World.OnWorldLoadFinishedEventHandler += new EventHandler(blah);
Are both equivalent?

User avatar
JunJayMdM
Reactions:
Posts: 262
Joined: April 2nd, 2012, 6:00 pm

Post by JunJayMdM » April 20th, 2014, 6:16 am

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 :)

icarus_allsorts
Reactions:
Posts: 213
Joined: March 8th, 2012, 6:00 pm

Post by icarus_allsorts » April 20th, 2014, 7:25 am

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.

User avatar
JunJayMdM
Reactions:
Posts: 262
Joined: April 2nd, 2012, 6:00 pm

Post by JunJayMdM » April 20th, 2014, 7:53 am

If that were the case though, his mod would not cooperate with any other mod using that event, all the NRaas mods for instance (except a couple of them), and people would have noticed.

Was that a typo in your previous post when you wrote World.OnWorldLoadFinishedEventHandler ?

User avatar
JunJayMdM
Reactions:
Posts: 262
Joined: April 2nd, 2012, 6:00 pm

Post by JunJayMdM » April 20th, 2014, 8:16 am

I checked his mod too, that line looks like a mistake, he forgot to add the "+" probably or whatever. Try adding your delegate later than OnWorldLoadFinished, perhaps with an alarm and see what happens.

User avatar
JunJayMdM
Reactions:
Posts: 262
Joined: April 2nd, 2012, 6:00 pm

Post by JunJayMdM » April 20th, 2014, 8:40 am

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

Post by icarus_allsorts » April 20th, 2014, 9:10 am

Thanks for checking! Yea, I'll probably do that or use some other way to hook the interaction onto the object. It's just odd that this is the ONLY mod using the event that I've seen that is affected by this, unless there is a specific order in which mods are loaded.

User avatar
JunJayMdM
Reactions:
Posts: 262
Joined: April 2nd, 2012, 6:00 pm

Post by JunJayMdM » April 20th, 2014, 9:44 am

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), &quot;Add OnObjectPlacedInLot&quot;, 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);
}
&nbsp;
static void OnAlarm()
{
World.OnObjectPlacedInLotEventHandler += new EventHandler(MyClass.OnObjectPlacedInLot);
}
&nbsp;
static void OnObjectPlacedInLot(object sender, EventArgs eventArgs)
{
//add interactions
}</pre>


Post Reply