Difference between revisions of "OnPlayerLoadGame - Actor"

366 bytes added ,  08:05, 22 June 2012
→‎Examples: Switched to global to kill two birds with one stone
imported>JustinOther
(→‎Examples: Added second example)
imported>JustinOther
(→‎Examples: Switched to global to kill two birds with one stone)
Line 22: Line 22:
endEvent
endEvent
</source>
</source>
*Say you need something to happen every time a save is loaded ''including'' the first and you're using a ReferenceAlias filled with the Player. In the below example, we maintain a variable such that it will invariably reflect the version loaded. Use an OnInit event in the quest's script to catch the first save load...
*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...
<source lang="papyrus">ScriptName YourQuestScript extends Quest
<source lang="papyrus">ScriptName YourQuestScript extends Quest
   
   
Float fVersion
GlobalVariable Property fYourModVersionGLOB Auto ; This will not reset in the the quest does and...


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