OnInit

From the CreationKit Wiki
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)
Jump to navigation Jump to search

Member of: Any and all scripts.

Event called when the script has been created and all its properties have been initialized.

Syntax

Event OnInit()

Example

; This is within the "empty" state
	EVENT onInit()                       ; This event will run once, when the script is initialized
		registerForUpdate(2)
		gotoState ("polling")
	endEVENT
	
 STATE polling	
	EVENT onUpdate()			
		if myQuest.getStage() == 10
			trace ("Got what we needed, so stop polling!")
			unregisterForUpdate()
			gotoState ("active")               ; switch to a state that doesn't use onUpdate()
		endif
	endEVENT
endSTATE

Parameters

None

Notes

  • Until OnInit has finished running, your script will not receive any events, and other scripts that try to call functions or access properties on your script will be paused until the event finishes. The only exceptions are when the functions are being called from another script inside its OnInit event, or inside a property set function being set by the master file.
  • OnInit is called at the following times:
    • For Quests and Aliases: On game startup, and again whenever the quest starts, due to the quest being reset.
    • For other base objects like Topic Infos, Perks, etc that have scripts that run on the base object: At game start
    • For persistent refs: At game start
    • For non-persistent refs: When the ref is loaded the first time
  • OnInit is called again when an object is reset. All your variables and properties will be reset before OnInit is called.
    • For Quests and Aliases this will happen when your quest starts. This means that a quest and alias will see OnInit twice before it starts the first time (game startup, and on reset). This should not cause any problems unless you are manipulating something outside the quest that doesn't reset in your OnInit.
    • For references this happens when the cell resets.

See Also

None