Jump to content

Calling the function of another script


mygames86

Recommended Posts

I am following this explanation to call the function of one script from another:

https://www.creationkit.com/index.php?title=OnPlayerLoadGame_-_Actor

 

PlayerAliasScript.psc

ScriptName PlayerAliasScript extends ReferenceAlias
 
QuestScript01 Property QuestScriptProperty01 Auto

Event OnPlayerLoadGame()
    Utility.Wait(5.0)
    debug.Notification("PlayerAliasScript OnPlayerLoadGame detected")
    QuestScriptProperty01.PlayerLoadedGame()
EndEvent

and

 

QuestScript01.psc

Scriptname QuestScript01 extends Quest

Event OnInit()
    Utility.Wait(25.0)
    debug.Notification("QuestScript01 OnInit detected")
EndEvent

function PlayerLoadedGame()
    debug.Notification("QuestScript01 PlayerLoadedGame detected")
EndFunction

I create a new quest, go to Quest Aliases, create a Specific Reference PlayerRef 14, attach the PlayerAliasScript to it

go to Scripts (from the quest itself), attack QuestScript01 to it.

 

Then I go back to PlayerAliasScript, open it and try to apply an object to the QuestScriptProperty01, but I can only select NONE here.

 

It do not understand why I cannot select QuestScript01???

 

In-game I get both the OnInit and OnPlayerLoadGame even to trigger.

 

Link to comment
Share on other sites

The player alias script is on an alias that is on the same quest as the quest script? If so, this is why. The alias script is basically reserving the quest from being selected. You can get around this by doing the following:

ScriptName PlayerAliasScript extends ReferenceAlias
 
QuestScript01 QuestScriptProperty01

Event OnPlayerLoadGame()
  QuestScriptProperty01 = GetOwningQuest() as QuestScript01
  Utility.Wait(5.0)
  debug.Notification("PlayerAliasScript OnPlayerLoadGame detected")
  QuestScriptProperty01.PlayerLoadedGame()
EndEvent
Link to comment
Share on other sites

Okay, I created a new quest, added under QuestAliases a PlayerRef, added the PlayerAliasScript,

then went back to the original quest, removed the PlayerRef there so it only contains the QuestScript01 under Scripts.

 

Still, as the property QuestScriptProperty01 from PlayerAliasScript I can only select NONE.

 

edit:
Someone the old quest was buggy, created a new quest where I attached the QuestScript01 script, and now I can add that quest as the property to the PlayerAliasScript.

Am I supposed to set quest as the value of the property QuestScriptProperty01 here? Cause in game the function PlayerLoadedGame isn't executed.

Edited by mygames86
Link to comment
Share on other sites

I hope the following breakdown will be helpful. If not, perhaps someone else can explain things better...

 

Givens:

  • Quest A has a script with a function you want to run.
  • Quest B has an alias with a script wanting to trigger the function on the script on Quest A

 

Assumptions:

  • Quest A script is called QuestAScript
  • Function on QuestAScript is called myQASFunction
  • Quest B alias script is called QuestBAliasScript

 

Solution:

Quest B alias script contents at minimum will be:

Scriptname QuestBAliasScript Extends ReferenceAlias
 
QuestAScript Property QAScript Auto
 
Event OnPlayerLoadGame()
  QAScript.myQASFunction()
EndEvent

 

Definitions / descriptons:

QAScript is the variable name used to refer to the actual QuestAScript. This property should have the desired object with the QuestAScript assigned to it.

If said object is a quest, it needs to be active in the game in order for the desired function to be ran.

If said object is a pre-placed object, it needs to be enabled and persistent (the property assignment will make it persistent by default) for the desired function to be ran.

Link to comment
Share on other sites

Oh man, finally got it to work.

 

Apparently the name of Quest A and the scriptname of the script attached to Quest A has to be identical.

 

Quest A name: AAAQuestAScript

Quest B name: AAAQuestBAliasScript

 

AAAQuestAScript.psc

Scriptname AAAQuestAScript extends Quest

Event OnInit()
	Utility.Wait(25.0)
;	debug.Notification("AAAQuestAScript OnInit detected")
EndEvent

function PlayerLoadedGame()
	debug.Notification("AAAQuestAScript PlayerLoadedGame detected")
EndFunction

PlayerAliasScript.psc

ScriptName PlayerAliasScript extends ReferenceAlias
 
AAAQuestAScript Property QAScript Auto

Event OnPlayerLoadGame()
	Utility.Wait(5.0)
	debug.Notification("PlayerAliasScript OnPlayerLoadGame detected")
	PlayerLoadedGame()
	QAScript.PlayerLoadedGame()
EndEvent

function PlayerLoadedGame()
	debug.Notification("PlayerAliasScript function PlayerLoadedGame detected")
EndFunction

 

Link to comment
Share on other sites

I never had to name my quests or other objects the same as the scripts to get this to work. Must be something else at play. Perhaps the plugin needed to be saved and the Creation Kit reloaded prior to referencing the one script in this manner. Wouldn't surprise me if the CK could not recognize a newly attached script.

Link to comment
Share on other sites

  • Recently Browsing   0 members

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