📜
PaperScript Docs
  • Welcome to PaperScript
  • Quick Start Guide
  • Syntax Reference
  • Feature Matrix
  • Feature Deep Dive
  • VSCode Extension
  • The Preprocessor
  • The project.yaml File
  • PaperScript CLI
    • Installing
    • Usage
  • Fallout 4 Support
  • Proposals
    • Naive Optimizations
  • Miscellaneous
    • Complete Example Scripts
Powered by GitBook
On this page
  • Defines
  • Conditionals
  • Substitution
  • Special Defines
  • Includes
Edit on GitHub
Export as PDF

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

#define PROJECT_NAME "Demo"
#define PROJECT_VERSION "1.0.0"

//...
Debug.Notification("Running PROJECT_NAME version PROJECT_VERSION")

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

#include "fragment.psc"
PreviousVSCode ExtensionNextThe project.yaml File

Last updated 2 days ago