Editing
Function Reference
(section)
Jump to navigation
Jump to search
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
== Accessing Functions From Other Scripts == There are several methods for accessing one script's functions (or properties, states, etc...) from another script. For the sake of the following examples, let us assume we are working on ScriptA, but we need to access a function that is in ScriptB. === Method One: Setting up the Target Script as a Filled Property === Declare the script that you want to access (ScriptB) ''as a property within'' the script you are trying to access it from (ScriptA). *This method is best when you only need access to a script that has a single instance (like a script attached to a specific Quest or ReferenceAlias). This is because you will have to choose the ''specific instance'' of the script you want to access when you fill the property in the CK. <br>'''Example:''' <syntaxhighlight lang="papyrus"> myRefAliasScript property refScript auto ;fill this property with your quest in the CK editor ;... refScript.myRefAliasScriptFunction01() refScript.myRefAliasScriptFunction02() ;access two functions that are in the reference alias script </syntaxhighlight> === Method Two: Access the Target Script by Creating a Variable On-the-fly === Declare a variable that has the type of the target script (ScriptB) that you want to access. Then set that variable to equal the instance of ScriptB that needs to be accessed. This method is best for times when: *(1) There are more than one instances of ScriptB that need to be differentiated (ScriptB is attached to several different Actors, for example) *(2) ScriptB does not exist before run-time, so a property cannot be filled with it (ScriptB is attached to an ObjectReference that doesn't exist until ScriptA PlaceAtMe()'s it into existence, for example) <br>'''Example One:'''<br> ''Access the script functions on a created ObjectReference:'' <syntaxhighlight lang="papyrus"> ObjectReference Pony1 = PlayerRef.PlaceAtMe(myCustomPony) ;create two ponies. Let us assume that myCustomPony is a base Actor that has 'PonyScript.psc' attached to it. ObjectReference Pony2 = PlayerRef.PlaceAtMe(myCustomPony) PonyScript Pony1Script = Pony1 as PonyScript ;declare two variables, each pointing to the INSTANCE of PonyScript attached to one particular pony PonyScript Pony2Script = Pony2 as PonyScript Pony1Script.groomPony() ;groom pony one, using the groomPony() function in (its instance of) PonyScript Pony2Script.killPony() ;kill pony two, using the killPony() function in (its instance of) PonyScript </syntaxhighlight> <br>Note: sometimes you will have to cast the object with ScriptB attached to it before declaring the variable will work. Let us say that Pony1 was an Actor instead of an ObjectReference, for instance. Since PonyScript extends ObjectReference, we first need to cast Pony1 ''as an ObjectReference'' before we can cast it ''as a PonyScript'', otherwise the compiler will throw out errors: <syntaxhighlight lang="papyrus"> Actor Pony1 = somePony PonyScript Pony1Script = (Pony1 as ObjectReference) as PonyScript </syntaxhighlight><br><br> '''Example Two:'''<br> ''Find an Actor's linked reference, and conditionally access the script functions on that reference:'' <syntaxhighlight lang="papyrus"> ObjectReference possibleTable1 = Actor1.GetLinkedRef() if (possibleTable1 as Furniture) == magicTable ;is the actor linked to a magicTable? magicTableScript TableScript1 = possibleTable1 as magicTableScript TableScript1.explode() ;if so, use the magicTable's script function to make the magicTable explode! endif </syntaxhighlight> <br><br>
Summary:
Please note that all contributions to the CreationKit Wiki are considered to be released under the Creative Commons Attribution-ShareAlike (see
CreationKit:Copyrights
for details). If you do not want your writing to be edited mercilessly and redistributed at will, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource.
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Navigation menu
Personal tools
Not logged in
Talk
Contributions
Create account
Log in
Namespaces
Page
Discussion
English
Views
Read
Edit
Edit source
View history
More
Search
Navigation
Landing page
Tutorials
Game Systems
Editor Reference
Scripting Reference
Recent changes
Help
Tools
What links here
Related changes
Special pages
Page information
Page values