RegisterForUpdate - Form: Difference between revisions

Jump to navigation Jump to search
m
Convert source tags to syntaxhighlight
m (→‎Notes: - corrected an error in my comment)
m (Convert source tags to syntaxhighlight)
 
Line 7: Line 7:


== Syntax ==
== Syntax ==
<source lang="papyrus">
<syntaxhighlight lang="papyrus">
Function RegisterForUpdate(float afInterval) native
Function RegisterForUpdate(float afInterval) native
</source>
</syntaxhighlight>


== Parameters ==
== Parameters ==
Line 20: Line 20:


== Examples ==
== Examples ==
<source lang="papyrus">
<syntaxhighlight lang="papyrus">
; Register to receive update events every 10 real-time seconds
; Register to receive update events every 10 real-time seconds
RegisterForUpdate(10.0)
RegisterForUpdate(10.0)
</source>
</syntaxhighlight>


== Notes ==
== Notes ==
Line 47: Line 47:
* The script is attached to something that is guaranteed to not stick around for long (for instance, a short duration magic effect). It is unlikely that a player will uninstall the mod in the middle of a fight that features mod content.
* The script is attached to something that is guaranteed to not stick around for long (for instance, a short duration magic effect). It is unlikely that a player will uninstall the mod in the middle of a fight that features mod content.
* When timing is critical. Due to script processing time, a chain of single updates takes an unpredictable and significant amount of additional time to execute. In cases where milliseconds matter (eg. when using continuous havok pushes to levitate objects or ragdolls), single updates may be unworkable. Again, make sure the script does not stick around for long. Remember that Delete() only actually deletes an object when the cell is unloaded!
* When timing is critical. Due to script processing time, a chain of single updates takes an unpredictable and significant amount of additional time to execute. In cases where milliseconds matter (eg. when using continuous havok pushes to levitate objects or ragdolls), single updates may be unworkable. Again, make sure the script does not stick around for long. Remember that Delete() only actually deletes an object when the cell is unloaded!
<source lang="papyrus">
<syntaxhighlight lang="papyrus">
function SomeInitializationFunction()
function SomeInitializationFunction()
     RegisterForSingleUpdate(0.5) ; OnUpdate will be called once.
     RegisterForSingleUpdate(0.5) ; OnUpdate will be called once.
Line 56: Line 56:
     RegisterForSingleUpdate(0.5) ; OnUpdate will be called one more time.
     RegisterForSingleUpdate(0.5) ; OnUpdate will be called one more time.
endEvent
endEvent
</source>
</syntaxhighlight>
It may also be wise to override the handler for [[OnPlayerLoadGame - Actor|OnPlayerLoadGame]]. That way, if OnUpdate previously contained an error and is no longer fired as a result, it will resume once the game is reloaded, hopefully with a modified version that fixes the problem. Note that this event is only fired on the player actor, on the ActiveMagicEffects put on the player and on the ReferenceAliases that reference the player.
It may also be wise to override the handler for [[OnPlayerLoadGame - Actor|OnPlayerLoadGame]]. That way, if OnUpdate previously contained an error and is no longer fired as a result, it will resume once the game is reloaded, hopefully with a modified version that fixes the problem. Note that this event is only fired on the player actor, on the ActiveMagicEffects put on the player and on the ReferenceAliases that reference the player.
<source lang="papyrus">
<syntaxhighlight lang="papyrus">
Event OnPlayerLoadGame()
Event OnPlayerLoadGame()
     RegisterForSingleUpdate(0.5)
     RegisterForSingleUpdate(0.5)
EndEvent
EndEvent
</source>
</syntaxhighlight>


== See Also ==
== See Also ==

Navigation menu