Script File Structure: Difference between revisions
imported>Whocares65 mNo edit summary |
m (Convert source tags to syntaxhighlight) |
||
| Line 15: | Line 15: | ||
=== Examples === | === Examples === | ||
< | <syntaxhighlight lang="papyrus"> | ||
; MyScript.psc | ; MyScript.psc | ||
ScriptName MyScript | ScriptName MyScript | ||
</ | </syntaxhighlight> | ||
<br> | <br> | ||
< | <syntaxhighlight lang="papyrus"> | ||
; HiddenScript.psc This script is hidden from the editor's normal script list, and extends ParentScript | ; HiddenScript.psc This script is hidden from the editor's normal script list, and extends ParentScript | ||
ScriptName HiddenScript Extends ParentScript Hidden | ScriptName HiddenScript Extends ParentScript Hidden | ||
</ | </syntaxhighlight> | ||
== Contents == | == Contents == | ||
| Line 34: | Line 34: | ||
=== Examples === | === Examples === | ||
< | <syntaxhighlight lang="papyrus"> | ||
; Call MyGlobal() in Utility, with no import | ; Call MyGlobal() in Utility, with no import | ||
Function MyFunction() | Function MyFunction() | ||
Utility.MyGlobal() | Utility.MyGlobal() | ||
EndFunction | EndFunction | ||
</ | </syntaxhighlight> | ||
<br> | <br> | ||
< | <syntaxhighlight lang="papyrus"> | ||
; Call MyGlobal() in Utility, with import | ; Call MyGlobal() in Utility, with import | ||
import Utility | import Utility | ||
| Line 48: | Line 48: | ||
MyGlobal() | MyGlobal() | ||
EndFunction | EndFunction | ||
</ | </syntaxhighlight> | ||
== Whitespace == | == Whitespace == | ||
| Line 54: | Line 54: | ||
=== Examples === | === Examples === | ||
< | <syntaxhighlight lang="papyrus"> | ||
; Valid use of white space (if perhaps not as readable) | ; Valid use of white space (if perhaps not as readable) | ||
x = (10+1* 2 ) as float | x = (10+1* 2 ) as float | ||
</ | </syntaxhighlight> | ||
<br> | <br> | ||
< | <syntaxhighlight lang="papyrus"> | ||
; Whitespace between the two equals signs in an equality operator will be interpreted as two equals signs, and fail to compile | ; Whitespace between the two equals signs in an equality operator will be interpreted as two equals signs, and fail to compile | ||
x = = 1 | x = = 1 | ||
</ | </syntaxhighlight> | ||
<br> | <br> | ||
< | <syntaxhighlight lang="papyrus"> | ||
; Whitespace between the 10 and 12 is interpreted as two numbers, 10 and 12, and not a single number 1012, and fail to compile | ; Whitespace between the 10 and 12 is interpreted as two numbers, 10 and 12, and not a single number 1012, and fail to compile | ||
10 12 | 10 12 | ||
</ | </syntaxhighlight> | ||
== Line Terminators == | == Line Terminators == | ||
| Line 73: | Line 73: | ||
=== Examples === | === Examples === | ||
< | <syntaxhighlight lang="papyrus"> | ||
; Two statements separated by a line terminator | ; Two statements separated by a line terminator | ||
x = 1 + 2 | x = 1 + 2 | ||
y = 2 * 3 | y = 2 * 3 | ||
</ | </syntaxhighlight> | ||
<br> | <br> | ||
< | <syntaxhighlight lang="papyrus"> | ||
; One long statement broken into two lines | ; One long statement broken into two lines | ||
x = 1 + 2 \ | x = 1 + 2 \ | ||
+ 3 + 4 | + 3 + 4 | ||
</ | </syntaxhighlight> | ||
<br> | <br> | ||
< | <syntaxhighlight lang="papyrus"> | ||
; Slash in this line is ignored, because it is in a comment \ | ; Slash in this line is ignored, because it is in a comment \ | ||
x = 1 + 2 ; This line isn't inside the above comment | x = 1 + 2 ; This line isn't inside the above comment | ||
</ | </syntaxhighlight> | ||
== Comments == | == Comments == | ||
| Line 98: | Line 98: | ||
==== Examples ==== | ==== Examples ==== | ||
< | <syntaxhighlight lang="papyrus"> | ||
; A simple single line comment | ; A simple single line comment | ||
</ | </syntaxhighlight> | ||
=== Multi-line Comments === | === Multi-line Comments === | ||
| Line 107: | Line 107: | ||
==== Examples ==== | ==== Examples ==== | ||
< | <syntaxhighlight lang="papyrus"> | ||
;/ A simple | ;/ A simple | ||
Multi-line comment /; | Multi-line comment /; | ||
| Line 114: | Line 114: | ||
y.DoCoolStuff() | y.DoCoolStuff() | ||
/; | /; | ||
</ | </syntaxhighlight> | ||
=== Documentation Comments === | === Documentation Comments === | ||
| Line 121: | Line 121: | ||
==== Examples ==== | ==== Examples ==== | ||
< | <syntaxhighlight lang="papyrus"> | ||
ScriptName MyCoolScript | ScriptName MyCoolScript | ||
{Documentation for my cool script here! | {Documentation for my cool script here! | ||
I can even use more than one line...} | I can even use more than one line...} | ||
</ | </syntaxhighlight> | ||
<br> | <br> | ||
< | <syntaxhighlight lang="papyrus"> | ||
int Property MyProperty Auto | int Property MyProperty Auto | ||
{This property is fun, if you set it to 1, watch cool stuff happen!} | {This property is fun, if you set it to 1, watch cool stuff happen!} | ||
</ | </syntaxhighlight> | ||
[[Category:Scripting]] | [[Category:Scripting]] | ||
[[Category:Papyrus]] | [[Category:Papyrus]] | ||
[[Category:Papyrus Language Reference]] | [[Category:Papyrus Language Reference]] | ||
Latest revision as of 21:18, 5 September 2026
<header line> (<import>|<variable definition>|<property definition>|<state definition>|<function definition>|<event definition>)*
A Papyrus script is a text file with the extension ".psc" that consists of a header line at the beginning of the file, followed by a collection of imports, variables, properties, states, functions, and events. The order of these elements is not important as long as the header line is the first non-comment line in the file.
Header Line[edit | edit source]
<Header Line> ::= 'ScriptName' <identifier> ['extends' <identifier>] (<flags>)*
The header line of the script consists of the keyword "ScriptName" followed by the identifier of the script (which must match the name of the file).
If the script extends another script, then the name of the script is followed by the "Extends" keyword and the name of the script it extends. And finally, by any flags.
Script Extension[edit | edit source]
Extending another script will let you override its functions and events to do something different, or add additional functionality while keeping the functionality of the older script. The only limitations are that any function or event in the child script whose name matches one in the parent script must have the same return type and parameter list.
Examples[edit | edit source]
; MyScript.psc
ScriptName MyScript
; HiddenScript.psc This script is hidden from the editor's normal script list, and extends ParentScript
ScriptName HiddenScript Extends ParentScript HiddenContents[edit | edit source]
The rest of the file, after the header, consists of imports, variable definitions, properties, states, functions, and events in any order. You do not have to define script variables, properties, functions, states, and events before you use them in the script. (Variables in functions and events, however, must be defined before use)
Imports[edit | edit source]
'Import' <identifier>
The "Import" keyword lets you use global functions in a script without prefixing them with the name of the script they are in. Simply use "Import" followed by the name of the script to import. If a function with the same name exists in both then you will still have to prefix it with the name of the script which contains the version you want.
Examples[edit | edit source]
; Call MyGlobal() in Utility, with no import
Function MyFunction()
Utility.MyGlobal()
EndFunction
; Call MyGlobal() in Utility, with import
import Utility
Function MyFunction()
MyGlobal()
EndFunctionWhitespace[edit | edit source]
Whitespace in Papyrus is unimportant, with the exception of line terminators which are explained below. Whitespace may be inserted anywhere as long as it doesn't split up a keyword, operator, literal or similar.
Examples[edit | edit source]
; Valid use of white space (if perhaps not as readable)
x = (10+1* 2 ) as float
; Whitespace between the two equals signs in an equality operator will be interpreted as two equals signs, and fail to compile
x = = 1
; Whitespace between the 10 and 12 is interpreted as two numbers, 10 and 12, and not a single number 1012, and fail to compile
10 12Line Terminators[edit | edit source]
Papyrus scripts are delineated into lines which determine where one statement ends and another begins. However, if you have a particularly long statement that you want to put on multiple lines, then you can add a "\" character to the end of the line and continue it on the next line. Slash characters inside comments are ignored (because everything in a comment is ignored), but you can put a comment after the slash if you wish
Examples[edit | edit source]
; Two statements separated by a line terminator
x = 1 + 2
y = 2 * 3
; One long statement broken into two lines
x = 1 + 2 \
+ 3 + 4
; Slash in this line is ignored, because it is in a comment \
x = 1 + 2 ; This line isn't inside the above commentComments[edit | edit source]
Comments in Papyrus come in three forms: Single line, multi-line, and documentation
Single-line Comments[edit | edit source]
<single line comment> ::= ';' <any text> <end of line>
Single line comments start with ";" and go until the end of the line. They consume all text after the semicolon, including any backslash characters that would otherwise let you continue onto the following line.
Examples[edit | edit source]
; A simple single line commentMulti-line Comments[edit | edit source]
<multi-line comment> ::= ';/' <any text> '/;'
Multi-line comments start with ";/" and consume any text (including newlines) until it finds "/;"
Examples[edit | edit source]
;/ A simple
Multi-line comment /;
;/ You can also have code in here, if you want to comment it out:
x = 2 * 1
y.DoCoolStuff()
/;Documentation Comments[edit | edit source]
<documentation comment> ::= '{' <any text> '}'
Documentation comments are special and can only appear on the line following a script header, property definition, or function definition. Documentation comments start at a "{" character and go until the terminating "}" character, including eating newlines and such. These comments show up as tooltips in the editor when you mouse over the script in the script picker, or when mousing over a property in the property editor.
Examples[edit | edit source]
ScriptName MyCoolScript
{Documentation for my cool script here!
I can even use more than one line...}
int Property MyProperty Auto
{This property is fun, if you set it to 1, watch cool stuff happen!}