The Preprocessor
The PaperScript preprocessor is a very experimental feature and it's really more of a post-processor because it runs after the code is transpiled so keep that in mind...
The PaperScript preprocessor works kind of like the C preprocessor but significantly simpler. It only supports a couple features at the moment but there are plans to expand it significantly in the future.
Defines
You can define a preprocessor variable with #define
. This variable can then be used in #if
s and anywhere in your code, where it will be substituted with the value.
Defines can be value-less, in which case the value is set to true
internally, or valued. Valued defines have a value enclosed in quotes.
Conditionals
With conditionals, it's possible to include / remove entire blocks of code based on the value of a define. This is very useful for, for example, debug build with more logging.
Substitution
Any mention of a define in your code will be substituted with its value. It's important to give your defines reasonably unique names so you don't accidentally replace something important.
Special Defines
There are some reserved define names that are either used to give additional instructions to the transpiler or set by the CLI internally.
OUTPUT_FILE_NAME
Overrides the output file name for the script it's in.
DEBUG
Can also be set from project.yaml
PROJECT_NAME
Set from project.yaml
PROJECT_VERSION
Set from project.yaml
Includes
You can include the contents of a different file.
The include functionality is extremely basic at the moment and included code does not get processed so if you want to include code, it needs to already be Papyrus, not PaperScript. This will be improved in the future.
The include path is relative to the file the include is in.
Last updated