Editing
Scripting Tutorial Using Functions
(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!
====Global Functions==== If you want to make some basic functions that everyone can use, and you don't want to have to have a scripted object in the world in order to use the function, you could make a Global Function. This function can be found in Custom.psc: <syntaxhighlight lang="Papyrus"> ;This function returns the Nth objectReference in a linked ref chain. ;The root link in the chain is 1 objectReference Function goToLink(int linkNum, objectReference startRef ) global int linkIndex = 1 while(linkNum != linkIndex ) linkIndex = linkIndex + 1 objectReference nextRef = startRef.getLinkedRef() if nextRef ;make sure that nextRef isn't "None" (i.e. the ref actually has a linked ref) startRef = nextRef else debug.trace( "Tried to access None link in custom.GoToLink()" ) endif endWhile return startRef endFunction </syntaxhighlight> So there are some more things going on here. This function starts at a ref in the world (the startRef parameter) and then counts through a chain of linked refs. How many linked refs should it cycle through before the function is done? Whatever value gets passed into the "linkNum" variable, it will try to count through that many linked refs. Then it will say that it's done, and will spit out that reference of the linkedRef chain. If you were to use this function, you could write something like this: <syntaxhighlight lang="Papyrus"> objectReference LinkInChain ;makes a new objectReference (like a ref in the old scripting language) called LinkInChain LinkInChain = goToLink( 3, someRefInTheWorld) </syntaxhighlight> This will start at some reference in the world (set up somewhere else in the script as to exactly what ref that is) and go to the third linked ref in the chain. Then you can set whatever reference the function found, and it places that in the LinkInChain variable.<br> You'll notice that the function declaration starts with "objectReference Function" instead of just "Function." This is because we want the function to return an objectReference so that we can know what the function found and place it in a variable.
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