Jump to content

[LE] Problem With OnPlayerLoadGame()


siashim

Recommended Posts

Hello everyone!

I am having some issues with OnPlayerLoadGame(). I followed the tutorial on creationkit.com complete sample scripts, but when I test the code in my game OnPlayerLoadGame() does not work.

I have a quest with Start Game Enabled and Run Once activated. The quest contains two scripts one a quest script and another a ReferenceAlias script. Here are the scripts:

Scriptname CRQC_VariableChangeScript extends Quest  
; assigns property with CompanionsHousekeepingScript in order to change its local variables
CompanionsHousekeepingScript Property CompanionsQuest Auto
int C01Check
int C03Check
int C04Check
Float fVersion
Float fNewVersion = 2.0
 
Event OnInit()
	Maintenance();
EndEvent

Function Maintenance()
	Debug.Notification("Maintenance...")
	if (fVersion < fNewVersion)
		Debug.Notification("inside if...")
		C01Check = 3
		C03Check = 6
		C04Check = 3
		fVersion = fNewVersion
	EndIf
	Debug.Notification("function call")
	RadiantQuestChange()
EndFunction

; changes local variables of CompanionsHousekeepingScript used by quest C00
Function RadiantQuestChange()
	Utility.Wait(2.0)
	CompanionsQuest.RadiantQuestsUntilC01 = C01Check
	Utility.Wait(2.0)
	CompanionsQuest.RadiantQuestsUntilC03 = C03Check
	Utility.Wait(2.0)
	CompanionsQuest.RadiantQuestsUntilC04 = C04Check
	Debug.Notification("function done")
EndFunction
Scriptname CRQC_PlayerAliasScript extends ReferenceAlias  
CRQC_VariableChangeScript Property QuestScript Auto
Event OnPlayerLoadGame()
	Debug.Notification("in update")
	QuestScript.Maintenance()
EndEvent

The first time I load a save that does not have the quest loaded yet, the first script runs. But after I make a save again, and load the new save the second script never runs. This means that I can't update the variables.

I also did test changing the version number, but that had no effect.

I would appreciate any help with this.

Link to comment
Share on other sites

Did you make a seq file? Did you verify that your alias is actually filling? And with the player? you can use the "sqv questname" console command to check the quest status.

Thanks, I was able to solve the issue. One of problem was that I was adding the ReferenceAlias script under the scripts, rather than to the specific alias. The other problem was that my alias was not filled with the player. I also had to remove fNewVersion, and instead change fVersion for every update. After fixing those issues I was able to make the quest work as intended.

Thanks again for your help.

Link to comment
Share on other sites

If you're trying to make it check version from release to release that's not going to work. The script vars are baked into the save once the script is instanced. So changing them in the script and compiling then releasing won't work. You can do a simple test to verify. Start a game, have it run the script, save. Update your version # and recompile, load save and see if the version got incremented. It wouldn't have.


To do a working version check it gets a little tricky but not hard. You need to make a GlobalVariable in CK and make it type const. You update that whenever you make changes. Then use that variable in a script like this:


J5gaV0i.png



Scriptname MyModUpdateHelperScript extends Quest

GlobalVariable Property zmCurrentVersion Auto
float fLastVersion = 0.0

Event OnInit()
float newVersion = zmCurrentVersion.GetValue()
if newVersion <= fLastVersion ; compares constant CK set global to local script
return ; instanced variable only run if newer. exit it not.
endif
Debug.Trace(self + ": Upgrading from version " + fLastVersion + " to " + newVersion)

fLastVersion = newVersion ; update the local script variable
EndEvent



Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...