OnPlayerLoadGame - Actor

From the CreationKit Wiki
Revision as of 08:05, 22 June 2012 by imported>JustinOther (→‎Examples: Switched to global to kill two birds with one stone)
Jump to navigation Jump to search

Member of: Actor Script (Requires 1.6)

Event called when the player loads a save game. This event is only sent to the player actor. If this is the first save game load where the event is being listened to, and the event is on an alias, and the alias didn't exist at the time the save was made, then the player won't be in the alias by the time the event is sent, and the alias script will not receive the event. It should then receive later events.

Syntax

Event OnPlayerLoadGame()

Parameters

None.

Examples

  • Syntax
; Event is only sent to the player actor. This would probably be on a magic effect or alias script
Event OnPlayerLoadGame()
  Debug.Trace("player loaded a save, do some fancy stuff")
endEvent
  • Say you need something to happen exactly once every time a save is loaded including the first and you're using a ReferenceAlias filled with the Player. In the below example with a "Start Game Enabled" quest, we maintain a GlobalVariable such that it will invariably reflect the version loaded. Use an OnInit event in the quest's script to catch the first save load...
ScriptName YourQuestScript extends Quest
 
GlobalVariable Property fYourModVersionGLOB Auto ; This will not reset in the the quest does and...

Event OnInit()
	If !fYourModVersionGLOB.GetValue() ; ...the global can be used as a DoOnce to prevent OnInit from firing twice
		fYourModVersionGLOB.SetValue(-1)
		Maintenance()
	EndIf
EndEvent
 
Function Maintenance()
	If fYourModVersionGLOB.GetValue() < 1.23 ; Current version
		If fYourModVersionGLOB.GetValue()
			Debug.Trace("Updating from version " + fYourModVersionGLOB.GetValue())
		Else
			Debug.Trace("Initializing for the first time.")
		EndIf
		fVersion = 1.23
	EndIf
EndFunction

...and your player alias' OnPlayerLoadGame event to catch each consecutive save load...

ScriptName YourPlayerAliasScript extends ReferenceAlias
 
YourQuestScript Property QuestScript Auto

Event OnPlayerLoadGame()
	QuestScript.Maintenance()
EndEvent

Notes

This event is only sent to the player actor. It is recommended that you handle this event via an alias the player is forced into, or a magic effect on the player.

See Also