The Preprocessor

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 #ifs 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.

#define DEBUG
#define PROJECT_VERSION "1.0.0"

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.

#define DEBUG

#if DEBUG
Debug.Notification("something happened")
#endif

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.

Define Name
Description

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 path is relative to the file the include is in.

Last updated