Receiving multiple OnObjectEquippedOnItemRemoved events

Post » Wed Jun 20, 2012 1:09 pm

In Frostfall, I use a "main quest" that contains a Player Alias, which has connected to it about 8 different scripts. Many of these have OnObjectEquipped events tied to them to look for different things being equipped to the player, as well as several that look for OnItemRemoved to know that certain things have been dropped.

The problem is that, for some reason, I occasionally (not always) receive multiple OnObjectEquipped and OnItemRemoved events for the same item, seemingly at random. I have been able to suppress this somewhat by using conditionals to block off certain sections of code until it's finished, but it doesn't always work.

Is there a reason I would be receiving multiple events like this? I can post script examples if necessary. I can understand all of my scripts receiving these events, which is fine, I have HasKeyword checks to filter that out; I just don't understand why the same event might be sent more than once.

Thanks!
User avatar
Love iz not
 
Posts: 3377
Joined: Sat Aug 25, 2007 8:55 pm

Post » Wed Jun 20, 2012 11:28 am

Not completely clear on exactly how events propogate...when an event occurs, all scripts that handle that event recieve it, right, multithreading if there's more than one, assuming that it's an event that is autoregistered or the script is registered for?

And what if one script registers for updates 10 seconds apart, and the other registers 15 seconds apart? would the updates come 10 seconds (the smaller) or 15, or would you get multiple overlapping updates at 10, 15, 20, 30 (2), etc? and would both scripts see all of them, or would each script only see the ones it was regisered for?
User avatar
Mr. Ray
 
Posts: 3459
Joined: Sun Jul 29, 2007 8:08 am

Post » Wed Jun 20, 2012 11:32 am

These are not OnUpdate or any event which requires registration. The Player Alias should send the "OnObjectEquipped" and "OnItemRemoved" event to every script that's attached to him, and if those scripts have that event, they process it. So it's a "push" model rather than a "pull" model (from the script's standpoint).

But to answer your question, there are certain conditions where 2 scripts that both are RegisterFor(Single)Update() will receive each other's OnUpdate() events http://www.gamesas.com/topic/1363978-bug-onupdate-event-fires-multiple-times-when-execution-time-exceeds-1-second/page__p__20581226#entry20581226.

Brilliant work with linked lists by the way, I've been meaning to tell you that.
User avatar
StunnaLiike FiiFii
 
Posts: 3373
Joined: Tue Oct 31, 2006 2:30 am

Post » Wed Jun 20, 2012 1:23 pm

Is your quest set to run once? Try doing that. I seem to remember quests that are not set to do this will actually on occasion initialize the scripts twice. Though I'm not sure if that's the actual cause of your issues.
User avatar
Samantha Mitchell
 
Posts: 3459
Joined: Mon Nov 13, 2006 8:33 pm

Post » Wed Jun 20, 2012 7:56 pm

Korjax, you pointed me in the right direction!

Here is what was happening. At the start of my mod, my quest (with associated reference aliases) starts off not running. I've since learned that this means nothing to scripts; they run anyway. Later on during play, when this quest is started, the scripts tied to it initialize again. This causes any events to be received twice by the player alias instead of once.

"Run Once" checked prevented the scripts from initializing again, but I still received duplicate events.

My solution was to simply never make the quest go running, as it was serving no purpose. It's only reason for being is to resolve the player to an alias and to hold scripts and properties.

Thanks!
User avatar
Devin Sluis
 
Posts: 3389
Joined: Wed Oct 24, 2007 4:22 am

Post » Wed Jun 20, 2012 8:10 pm

resolved, closed by request
User avatar
Eileen Collinson
 
Posts: 3208
Joined: Thu Dec 28, 2006 2:42 am


Return to V - Skyrim