From ZDoom Wiki
Jump to navigation Jump to search

ZScript (formerly known as DoomScript) is a text-based lump used to create classes, structs, and custom functionality for use in ZDoom. It is similar to Java and C# in many ways and allows for more advanced control of all gameplay facets (Actors, levels, game modes, etc.) than DECORATE does.

You can include other lumps for processing with either a full or relative path to said lumps. A relative path starts with either ./ or ../:

// Full path
#include "ZScript/Const.txt"
// Relative paths
#include "./Items/Health.txt" // Start from the current directory this file is located in
#include "../Items/Armor.txt" // Start from the parent directory this file is located in

Due to how ZScript is processed, it is possible to name a file which conflicts with other mods or the internal files. For example, if you have a file in your mod with path ZScript/Const.txt, it will prevent the game from loading this file correctly as ZDoom itself already defines that file within its own ZScript subfolder. To avoid such conflicts, it is recommended to have a subfolder named after your mod, such as:

#include "MyMod/Const.txt"

As of GZDoom 2.3.0, ZScript is enabled by default and does not require any command-line parameter. The last development versions of ZDoom past 2.8.1 require the -zscript command line parameter to enable loading of ZScript lumps.

A full ZScript file is known as a translation unit, akin to the C programming language's definition of the term.

Note: All keywords and identifiers in ZScript are case insensitive.

Load order

ZScript is much more relaxed and includes can be done in any order, except for extending classes.

Combining ZScript and DECORATE

It is possible to use both DECORATE and ZScript simultaneously. For example, ZScript might be used to create some custom function which is then available to regular DECORATE actors. The ZScript code is processed and compiled before the DECORATE code; this means that DECORATE actors can inherit from ZScript actors, but not vice-versa. For references that are only needed at run-time rather than compile-time (such as calling a function to spawn an actor), there is no restriction: a ZScript actor can spawn a DECORATE actor, or vice-versa.

ZScript topics

Advanced topics

These sections are for advanced users and programmers who want more control over their mods. The best course of action for modders would be to brush up on a programming language like Java or C#. These topics will assume all who read them know how to work with ZScript, preferably most of the above information.

Also consider opening the gzdoom.pk3 with any application that can browse ZIP files. The base file contains all manner of ZScript code which the modder can learn from as examples.

ZScript guides

Additional documentation

In case any of the above pages do not answer your questions, Marrub has been working on more detailed and comprehensive documentation for ZScript's core language and API. This is a work in progress, but will be added to the wiki when complete. Until then, this additional documentation may be found at the following link: https://github.com/marrub--/zscript-doc/blob/master/README.md