Jump to content

[LE] How to cancel an OnUpdate() Call


BarnsleyLad

Recommended Posts

Speaking hypothetically, lets say I have a script that is registered to update every 60 seconds, and that this script also checks for an animation event... Upon this animation, I wish to unregister the OnUpdate() call immediately, and re-register to update every 5 seconds this time. In my experience, it seems that, even though I have called UnregisterForUpdate(), the script only unregisters once the time remaining in the 60 second update has passed...Is there a way to bypass this? Does UnregisterForUpdate() cancel an update call half way through its timer? Is there something else going on here? And should I maybe switch to a SingleUpdate loop? Many Thanks!!!

Link to comment
Share on other sites

You should always use single update loops, as they are safer. With a single update loop you could do something like this:

 

Float Updatetime = 60.0

Event OnInit() 
    RegisterForSingleUpdate(Updatetime)
    RegisterForAnimationEvent(self, "Some event")
EndEvent 

Event OnAnimationEvent(ObjectReference akSource, String asEventName)
    UnregisterForUpdate()
    Updatetime = 5.0
    RegisterForSingleUpdate(Updatetime)
EndEvent

Event OnUpdate()
    ;do something
    RegisterForSingleUpdate(Updatetime)
EndEvent
Link to comment
Share on other sites

FYI - A new single update will override a previous single update that has not reached its timer. In dylbill's example, you will start out with a 60 second update cycle. Once the animation event is triggered, the update cycle will change to 5 seconds starting from that point of registration. If you want the update cycle to revert to 60 at some point, you will need to have the appropriate checks in place to change the duration with a new registration call.

Link to comment
Share on other sites

 

You should always use single update loops, as they are safer. With a single update loop you could do something like this:

 

Float Updatetime = 60.0

Event OnInit() 
    RegisterForSingleUpdate(Updatetime)
    RegisterForAnimationEvent(self, "Some event")
EndEvent 

Event OnAnimationEvent(ObjectReference akSource, String asEventName)
    UnregisterForUpdate()
    Updatetime = 5.0
    RegisterForSingleUpdate(Updatetime)
EndEvent

Event OnUpdate()
    ;do something
    RegisterForSingleUpdate(Updatetime)
EndEvent

 

 

 

FYI - A new single update will override a previous single update that has not reached its timer. In dylbill's example, you will start out with a 60 second update cycle. Once the animation event is triggered, the update cycle will change to 5 seconds starting from that point of registration. If you want the update cycle to revert to 60 at some point, you will need to have the appropriate checks in place to change the duration with a new registration call.

Thanks you two, this is exactly what I was looking for! I had wondered if single updates where the way to go, seems like the normal update method is way too finicky with stack management, and I have heard that it is an easy way to bloat your save file, glad you lot could steer me right :smile: Cheers for the help

Edited by BarnsleyLad
Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...