OnInit

From the CreationKit Wiki
Revision as of 18:59, 22 January 2019 by imported>XJDHDR (→‎Example: Simplified and fixed the state switching examples.)
Jump to navigation Jump to search

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