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!
====Local Functions==== You can declare functions locally. That means that these functions live inside of one particular script, and can only be run if you have a specific script to run the function in. <syntaxhighlight lang="Papyrus"> ;inside some script... float value = 3.0 Function ModifyValue(float valueModifier) value = (value + 2.0) * valueModifier EndFunction Event OnActivate(ObjectReference actionRef) ModifyValue(5.0) EndEvent </syntaxhighlight> There are a few things going on here: *'''Function''' - this is called to start a function declaration *'''ModifyValue''' - this is the name of the function that you're making *'''float valueModifier''' - here you are declaring a parameter. In this case, it means that you can pass a float in as a parameter for the function. Inside the function, you can use the variable "valueModifier" and that will be whatever number that gets passed into the function. *'''value = (value + 2.0) * valueModifier''' - this is some logic inside the function. You could put any logic in here that you want. As you see, I'm using "valueModifier" like it's a variable. We don't know what the value of this variable is, however, as anything could be passed in. *'''EndFunction''' - This ends the function declaration. With a local function, you would have to actually have a scripted object in the world in order to use the function. This particular script has a variable called "value" in it, and if you're inside the script you can call ModifyValue() to change "value" to a different number. A different script can also call ModifyValue() on this script as well, and it would actually change the number stored in "value". A different script could use this script's function. <BR><BR>In this example, "value" would get set to 25.0 when you activate the scripted object for the first time.
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