1,482
edits
imported>Jlundin (Added coloring tags) |
m (Convert source tags to syntaxhighlight) |
||
| Line 6: | Line 6: | ||
====Local Functions==== | ====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. | 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... | ;inside some script... | ||
float value = 3.0 | float value = 3.0 | ||
| Line 17: | Line 17: | ||
ModifyValue(5.0) | ModifyValue(5.0) | ||
EndEvent | EndEvent | ||
</ | </syntaxhighlight> | ||
There are a few things going on here: | There are a few things going on here: | ||
*'''Function''' - this is called to start a function declaration | *'''Function''' - this is called to start a function declaration | ||
| Line 28: | Line 28: | ||
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. | 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: | This function can be found in Custom.psc: | ||
< | <syntaxhighlight lang="Papyrus"> | ||
;This function returns the Nth objectReference in a linked ref chain. | ;This function returns the Nth objectReference in a linked ref chain. | ||
;The root link in the chain is 1 | ;The root link in the chain is 1 | ||
| Line 44: | Line 44: | ||
return startRef | return startRef | ||
endFunction | 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. | 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: | 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 | objectReference LinkInChain ;makes a new objectReference (like a ref in the old scripting language) called LinkInChain | ||
LinkInChain = goToLink( 3, someRefInTheWorld) | 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> | 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. | 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. | ||
| Line 58: | Line 58: | ||
Native functions are defined in code. In the old scripting language, every function was defined in code so there wasn't a need for distinction. | Native functions are defined in code. In the old scripting language, every function was defined in code so there wasn't a need for distinction. | ||
<br>Here is an example of a native function being declared in the Debug.psc script: | <br>Here is an example of a native function being declared in the Debug.psc script: | ||
< | <syntaxhighlight lang="Papyrus"> | ||
; Outputs the string to the VS debugger | ; Outputs the string to the VS debugger | ||
Function Trace(string asTextToPrint) native global | Function Trace(string asTextToPrint) native global | ||
</ | </syntaxhighlight> | ||
Now, there are some keywords in here that we should go over. | Now, there are some keywords in here that we should go over. | ||