1,482
edits
m (→Notes: - corrected an error in my comment) |
m (Convert source tags to syntaxhighlight) |
||
| Line 7: | Line 7: | ||
== Syntax == | == Syntax == | ||
< | <syntaxhighlight lang="papyrus"> | ||
Function RegisterForUpdate(float afInterval) native | Function RegisterForUpdate(float afInterval) native | ||
</ | </syntaxhighlight> | ||
== Parameters == | == Parameters == | ||
| Line 20: | Line 20: | ||
== Examples == | == Examples == | ||
< | <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) | ||
</ | </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! | ||
< | <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 | ||
</ | </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. | ||
< | <syntaxhighlight lang="papyrus"> | ||
Event OnPlayerLoadGame() | Event OnPlayerLoadGame() | ||
RegisterForSingleUpdate(0.5) | RegisterForSingleUpdate(0.5) | ||
EndEvent | EndEvent | ||
</ | </syntaxhighlight> | ||
== See Also == | == See Also == | ||