OnUpdate - Form

Revision as of 15:26, 18 October 2011 by imported>Rhavlovick (1 revision: Clobber re-import by Henning)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Member of: ActiveMagicEffect Script, Alias Script, and Form Script

Event called periodically if the active magic effect/alias/form is registered for update events. This event will not be sent if the game is in menu mode.

Syntax

Event OnUpdate()

Parameters

None

Example

Function SomeFunction()                
  registerForUpdate(5) ; Before we can use onUpdate() we must register.
EndFunction
	
Event OnUpdate() ; because of how we registered, this event occurs every five seconds		
  If myQuest.getStage() == 10
    UnregisterForUpdate()  ; when we're done with it, make sure to unregister
    Debug.Trace("Got what we needed, so stop polling!")
  EndIf
EndEvent

Notes

  • Aliases and quests will automatically unregister for this event when the quest stops. Active magic effects will automatically unregister when they are removed.
  • This event is not relayed to any aliases or magic effects attached to the form.
  • Be careful with the use of this event. Because it uses real-time, it can start piling up on itself if the OnUpdate doesn't finish before the time is up. To avoid this, try using a longer time at registration, or do a 'single update chain' which looks like the following:
Function StartChain()
  RegisterForSingleUpdate(1) ; Give us a single update in one second
endFunction

Event OnUpdate()
  bool bkeepUpdating = true
  ; Do stuff here, and update the bkeepUpdating variable depending on whether you want another update or not
  if bkeepUpdating
    RegisterForSingleUpdate(1)
  endIf
endEvent

This prevents multiple update events from stacking up on top of each other and slowing Papyrus down.

See Also