"RegisterForSingleUpdate()"

Post » Mon Nov 19, 2012 9:05 am

I've heard that putting "RegisterForSingleUpdate()" at the start of an "OnUpdate()" block can cause bloating if the functions below it fail to finish by the time the next update occurs.

Is that true? Because my script fails to register itself for update again after it finishes its functions, so registering before the functions are called should keep it running like it needs.
User avatar
Stefanny Cardona
 
Posts: 3352
Joined: Tue Dec 19, 2006 8:08 pm

Post » Mon Nov 19, 2012 11:20 pm

I'd put the RegisterForSingleUpdate after the function/event body rather than before it to ensure said threading issued do not arise. Post the code?
User avatar
Ymani Hood
 
Posts: 3514
Joined: Fri Oct 26, 2007 3:22 am

Post » Mon Nov 19, 2012 1:50 pm

Event OnUpdate()RegisterForSingleUpdate(60)if (pCWAttackCity.IsRunning()) && (pCWAttackCity.GetStage() < 50)  if !(Alias_CWAttackCityJarl.GetRef())   Alias_CWAttackCityJarl.ForceRefTo(CWAttackCityJarl.GetRef())  endifelseif (Alias_CWAttackCityJarl.GetRef())  Alias_CWAttackCityJarl.Clear()endifif (pFreeformRiften01.GetStage() == 200) || (pFreeformRiften20.GetStage() == 250)  Alias_FreeformRiften01Jarl.UnregisterForUpdate()endifif (pFreeformRiftenThane.GetStage() == 200) || (pFreeformRiften20.GetStage() == 250)  Alias_FreeformRiftenThaneJarl.UnregisterForUpdate()endifif (pCWPostWhiterunObj.GetStage() == 100)  Alias_CWPostWhiterunObjJarl.UnregisterForUpdate()endifif (pMS14.GetStage() == 200)  Alias_MS14Jarl.UnregisterForUpdate()endifGoToState("checking")CheckEssentials()CheckEssentialAliases()GoToState("")endEventSTATE checkingEvent OnUpdate()  RegisterForSingleUpdate(60)endEventendSTATE

I'd assume the trouble comes from the scripting "missing a beat" while handling the "CheckEssentials" and "CheckEssentialAliases" functions, which make heavy use of arrays.

It un-registered without the state changes, which is how it was originally written. Do you think the state changes will help?
User avatar
Meghan Terry
 
Posts: 3414
Joined: Sun Aug 12, 2007 11:53 am

Post » Mon Nov 19, 2012 2:44 pm

Using the state is probably just hiding a bigger problem. If the following doesn't work, then one of your Check functions isn't actually finishing. If that's the case, you need to find that problem and fix it.
Event OnUpdate()if (pCWAttackCity.IsRunning()) && (pCWAttackCity.GetStage() < 50)  if !(Alias_CWAttackCityJarl.GetRef())   Alias_CWAttackCityJarl.ForceRefTo(CWAttackCityJarl.GetRef())  endifelseif (Alias_CWAttackCityJarl.GetRef())  Alias_CWAttackCityJarl.Clear()endifif (pFreeformRiften01.GetStage() == 200) || (pFreeformRiften20.GetStage() == 250)  Alias_FreeformRiften01Jarl.UnregisterForUpdate()endifif (pFreeformRiftenThane.GetStage() == 200) || (pFreeformRiften20.GetStage() == 250)  Alias_FreeformRiftenThaneJarl.UnregisterForUpdate()endifif (pCWPostWhiterunObj.GetStage() == 100)  Alias_CWPostWhiterunObjJarl.UnregisterForUpdate()endifif (pMS14.GetStage() == 200)  Alias_MS14Jarl.UnregisterForUpdate()endifCheckEssentials()CheckEssentialAliases()RegisterForSingleUpdate(60)endEvent
I would put a few Notification or Trace statements before and after your check functions (and possibly inside of them too) just to see what's really happening.
User avatar
lilmissparty
 
Posts: 3469
Joined: Sun Jul 23, 2006 7:51 pm

Post » Mon Nov 19, 2012 6:13 pm

Actually, I edited the script to show debug message boxes -- all functions were finishing correctly.

I kept the re-registering at the start of the OnUpdate() and the state changes -- message boxes indicated it never actually wanted to update in the "checking" state, but just in case...

It's pretty telling that the save that was having the issue proceeded to CTD once the OnUpdate() ran. Perhaps it was a one-off.
User avatar
Lillian Cawfield
 
Posts: 3387
Joined: Thu Nov 30, 2006 6:22 pm


Return to V - Skyrim