Jump to content

Accessing external function/variable


nexusMods3

Recommended Posts

I have a script attached to a player, and a script attached to a quest. How can I make the script attached to the quest access a variable/function on the script attached to the player? I've been trying to do that for hours now and I just can't. If someone can give me a detailed explanation, I would appreciate very much. I made a mod, the mod is done, but I want to make it compatible with MCM. The config option the user would be able to tweak is the letter to activate the mod. So I'm using the OnOptionKeyMapChange to do that, but on that event, I want to have access to the variable/function in the script attached to the player. The quest has the player as an alias, if that helps. Thank you.

Link to comment
Share on other sites

I explained this once before in great detail, but unfortunately I can't find that post.

 

This assumes the player's script is named PlayerScript and that it is attached to an alias named PlayerAlias on the same quest.

Scriptname PlayerScript extends ReferenceAlias

Float Function GetSomeInformation()
	Return GetActorRef().GetAV("Health")
EndFunction
Scriptname QuestScript extends Quest

ReferenceAlias Property PlayerAlias Auto

Event OnInit()
	Debug.Notification((PlayerAlias as PlayerScript).GetSomeInformation())
EndEvent

The thing to note is that you have to cast the property or variable containing the alias reference as the script name with the function. This will make the functions and variables available for use because it forced the variable to extend the script. See, when you use "GetRef as Actor", "Actor" is literally just a script, and you're doing the exact same thing, except the script you're extending in your case is a custom one.

EDIT: I managed to find it. http://forums.nexusmods.com/index.php?/topic/1264015-a-question-answered-completing-a-quest-objective-when-player-levels-up-and-other-scripts/?p=10575817 It's not much better than what I already posted, but it does have a small explanation.

Edited by Xander9009
Link to comment
Share on other sites

Thanks for the reply. Good to know there is another way. After reading in the creation kit website: "A Property is essentially a variable that other scripts can access", I realized I could just create a property of the script type that had the functions and variables I wanted to use...and it worked lol :p

Link to comment
Share on other sites

  • Recently Browsing   0 members

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