mygames86 Posted September 23, 2021 Share Posted September 23, 2021 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 itgo 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 More sharing options...
IsharaMeradin Posted September 23, 2021 Share Posted September 23, 2021 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 More sharing options...
mygames86 Posted September 23, 2021 Author Share Posted September 23, 2021 (edited) 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 September 23, 2021 by mygames86 Link to comment Share on other sites More sharing options...
IsharaMeradin Posted September 23, 2021 Share Posted September 23, 2021 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 QuestAScriptFunction on QuestAScript is called myQASFunctionQuest 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 More sharing options...
mygames86 Posted September 23, 2021 Author Share Posted September 23, 2021 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: AAAQuestAScriptQuest 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 More sharing options...
IsharaMeradin Posted September 23, 2021 Share Posted September 23, 2021 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 More sharing options...
mygames86 Posted September 24, 2021 Author Share Posted September 24, 2021 Okay, just to clear up any misunderstandings, per MagicEffect, Quest, ActorRef etc. I can only attach one script? Link to comment Share on other sites More sharing options...
IsharaMeradin Posted September 24, 2021 Share Posted September 24, 2021 You can attach as many scripts as necessary to a single object. However, if multiple such scripts are running the same event, it may be better to combine them into a single script. Link to comment Share on other sites More sharing options...
mygames86 Posted September 24, 2021 Author Share Posted September 24, 2021 Oh sorry, the question was phrased badly.I mean if I want to access the script so i can e.g. call functions from it, it has to be the only script attached to an object? Link to comment Share on other sites More sharing options...
IsharaMeradin Posted September 25, 2021 Share Posted September 25, 2021 There can be more than one script on the object and still have the ability to remotely access functions on the targeted script. Link to comment Share on other sites More sharing options...
Recommended Posts