Difference between revisions of "OnInit"
Jump to navigation
Jump to search
imported>XJDHDR m (Undid 2 revisions by User:DavidJCobb: I disagree. The OnUpdate block is for code that would be in OnInit if it weren't for scripts not receive any events until OnInit finishes. Thus, it runs once.) |
imported>XJDHDR (→Example: Simplified and fixed the state switching examples.) |
||
Line 1: | Line 1: | ||
== Example == | == Example == | ||
This example uses state switching to run our OnInit code. | This example uses state switching to run our OnInit code. | ||
Line 16: | Line 4: | ||
; This is within the "empty" state | ; This is within the "empty" state | ||
Event OnInit() ; This event will run once, when the script is initialized | Event OnInit() ; This event will run once, when the script is initialized | ||
GotoState("InitStart") | |||
EndEvent | EndEvent | ||
State InitStart | State InitStart | ||
Event OnBeginState() | Event OnBeginState() | ||
Debug.Trace("OnInit code started") | |||
; Do everything we need to here | |||
GotoState("") | |||
EndEvent | EndEvent | ||
Event OnInit() | |||
EndEvent | |||
EndState | EndState | ||
</source> | </source> | ||
Line 45: | Line 27: | ||
Event OnUpdate() | Event OnUpdate() | ||
Debug.Trace("OnInit code started, so stop polling!") | |||
UnregisterForUpdate() | |||
; Do everything we need to here | |||
GotoState("active") ; Switch to a state that doesn't use OnUpdate() | |||
EndEvent | EndEvent | ||
Line 58: | Line 39: | ||
EndState | EndState | ||
</source> | </source> | ||
Revision as of 18:59, 22 January 2019
Example
This example uses state switching to run our OnInit code.
; This is within the "empty" state
Event OnInit() ; This event will run once, when the script is initialized
GotoState("InitStart")
EndEvent
State InitStart
Event OnBeginState()
Debug.Trace("OnInit code started")
; Do everything we need to here
GotoState("")
EndEvent
Event OnInit()
EndEvent
EndState
This script uses an OnUpdate event to run our OnInit code.
; This is within the "empty" state
Event OnInit() ; This event will run once, when the script is initialized
RegisterForSingleUpdate(2.0)
EndEvent
Event OnUpdate()
Debug.Trace("OnInit code started, so stop polling!")
UnregisterForUpdate()
; Do everything we need to here
GotoState("active") ; Switch to a state that doesn't use OnUpdate()
EndEvent
State active
Event OnUpdate()
; Do nothing in here.
EndEvent
EndState