Confusion with RegisterForSingleUpdate

Post » Tue Feb 18, 2014 1:31 am

My understanding was that this function would register for an update to occur X seconds in the future, whereupon the OnUpdate Event would be called. It would do this only once, unless, during the course of script execution, another RegisterForSingleUpdate was encountered. So here is a small bit of script which highlights the problem I'm having:

Spoiler
Scriptname BScript02 extends Perk Event OnInit()Debug.Notification("OnInit")Utility.Wait(10.0)BMain()endEvent Function BMain()Debug.Notification("BMain")Utility.Wait(10.0)RegisterForSingleUpdate(1.0)EndFunction Event OnUpdate()Debug.Notification("OnUpdate")Utility.Wait(10.0)Debug.Notification("First wait over.")Utility.Wait(10.0)RegisterForSingleUpdate(0.5)endEvent

(That's the whole script.) Now, from where I'm standing, the above code should give the following result:

"OnInit", (10 seconds), "BMain", (10 seconds), "OnUpdate", (10 seconds), "First wait over.", (10.5 seconds), "OnUpdate" ... (loop)

What I instead get is the following (times are approximated):

"OnInit", (10 seconds), "BMain", (10 seconds), "OnUpdate", (5 seconds), OnUpdate (5 seconds), "First wait over.", "OnUpdate" (5 seconds), "First wait over.", "OnUpdate" ...

My interpretation (interpretation - not explanation) of this result is that the RegisterForSingleUpdate in the OnUpdate Event is being called at will, ignoring the 20 second delay purposefully put in there, causing a cascade of multiple, simultaneous instances of the OnUpdate Event. How this happens, and why it seems to happen at a particular interval (5 seconds??) are just further points of confusion.

Was I mistaken as to how the RegisterForSingleUpdate function is meant to work? Does the function have this ability to ignore the script at large and call itself willy nilly at difficult-to-control moments?

User avatar
Jose ordaz
 
Posts: 3552
Joined: Mon Aug 27, 2007 10:14 pm

Post » Mon Feb 17, 2014 6:24 pm

Much more likely you are showing up the weakness of Debug.Notification() instead.

User avatar
STEVI INQUE
 
Posts: 3441
Joined: Thu Nov 02, 2006 8:19 pm

Post » Mon Feb 17, 2014 2:16 pm

Well.. it's still an incontrovertible fact that I get multiple "OnUpdate" notices in a row, way less than 20 or even 10 seconds separated. I made some further troubleshooting steps - took the RegisterForSingleUpdate out of the OnUpdate, threw in time notices, replaced Utility.Wait with something more reliable - so the full script now looks like this:

Spoiler
Scriptname BScript02 extends Perk Event OnInit()Debug.Notification("OnInit - currenttime is " + Utility.GetCurrentRealTime())CustomWait(10.0)BMain()endEvent Function BMain()Debug.Notification("BMain - current time is " + Utility.GetCurrentRealTime())CustomWait(10.0)RegisterForSingleUpdate(1.0)EndFunction Event OnUpdate()BMain2()endEvent Function BMain2()Debug.Notification("OnUpdate - current time is " + Utility.GetCurrentRealTime())CustomWait(10.0)Debug.Notification("First wait over - current time is " + Utility.GetCurrentRealTime())CustomWait(10.0)RegisterForSingleUpdate(0.5)endFunction Function CustomWait(float HowLong)float WaitingHowLong = Utility.GetCurrentRealTime()While (Utility.GetCurrentRealTime() < (WaitingHowLong + HowLong))Utility.Wait(0.2)endWhileendFunction
It made no difference. The 5-second interval must have been a fluke, because the timing notices suggest the actual interval is in close agreement with the delay I set up in the RegisterForSingleUpdate (0.5 seconds). So it pings "OnUpdate" like 20 times before I see the first "First wait over". Why? Why is RegisterForSingleUpdate happening every 0.5 seconds regardless of the fact that the script hasn't made it to that point yet? I might understand this phenomenon if this was a RegisterForUpdate, but it is not.
User avatar
Arnold Wet
 
Posts: 3353
Joined: Fri Jul 07, 2006 10:32 am


Return to V - Skyrim