githubEdit

Syntax Reference

Script Block

A script is contained in a script block. This is equivalent to ScriptName extends... in Papyrus. The only thing that can go before a script block are comments and defines.

#define HELLO_WORLD

// The colon replaces the "extends"
script Demo : ObjectReference {}

States

A state is a block with a name and an optional auto flag.

circle-info

See the CK Wiki State Documentationarrow-up-right for more in-depth information

auto state DefaultState {
  // ...
}

state OtherState {
  // ...
}

Imports

Importing a script allows you to use its Global functions without having to prefix them with the script name.

circle-info

Properties

A property is a script-scoped variable that's available to external scripts. A property itself does not actually store anything, it's an interface between a script's private variable and the outside world.

Auto Properties

Auto properties represent a private variable and a basic setter like the one above. An auto property starts with auto property and then follows the regular variable format. They can optionally have a default value.

Variables

Variable definitions begin with a name, followed by a type and finally an optional value. Since Papyrus doesn't do type inference, types must be explicitly defined. (Type inference is a future planned feature of PaperScript)

circle-info

If you don't specify a value, the variable will be filled with the Papyrus default for that type.

Functions

A function starts with def, has a name, optional arguments and an optional return type. Functions that don't have a return type (void), don't need to specify one.

Events

Events work the same as functions but start with event instead of def and never have a return type.

Conditionals

The If/ElseIf/Else syntax is virtually identical to Papyrus but with braces. Parentheses are optional and only used to denote precedence.

circle-check

While

The while syntax is the same as Papyrus but with braces. Parentheses are once again optional and used for precedence.

Increment / Decrement

PaperScript has a simple implementation of the increment and decrement operators. It's basically just shorthand for adding or subtracting 1 from an int.

Switch

A switch is one of the features sorely missing from Papyrus. PaperScript supports switch statements that get translated into if/elseif/else in the resulting Papyrus.

Cases can be single-line or multi-line. Single-line cases must end with a semicolon. Multi-line cases are in braces.

The default case follows the same pattern and will match anything that doesn't have a case.

Cases do not fall through and there is no break

circle-exclamation

Range

range is another new addition to PaperScript that doesn't exist in Papyrus. It works as a foreach loop and gets translated into a while in the resulting Papyrus.

circle-exclamation

Array Initializers

This is a small quality of life improvement that makes a big difference. Initializing arrays with data is pretty annoying in Papyrus and PaperScript makes it a lot simpler.

Struct Initializers

Just as with arrays, filling structs with data is kinda annoying in Papyrus as well. PaperScript simplifies this too.

circle-exclamation

Last updated