ZScript classes

From ZDoom Wiki
Jump to: navigation, search
Note: This feature is for ZScript only.

ZScript classes are similar to C++ classes which may contain a variety of data.

Internal classes

Below is a list of internal classes used in ZDoom. Classes inheriting from other classes use a colon, much like how DECORATE performs inheritance. These classes are only accessible to ZScript itself (save for Actor)

Cross-Mod Support

Currently there is not much ability to check between loading different mods on top of primary ones (like addons), but there is a way to check if a class exists.

// Checked at compile time. This will error upon loading if the class is missing.
class<Actor> cls = "MissingNameOfClass";
// Checked at run time instead of compile time. 'cls' will just be null if the actor class isn't defined.
string classname = "MissingNameOfClass";
class<Actor> cls = classname;

Class names are checked at compile time by default. However, using a string in place of a name forces the engine to rely upon run-time instead. A simple check will allow compatibility for addons:

if (cls)

Extending Classes

Classes may be extended, but the class must be part of the same mod. I.e. one can have extensions occur in a separate file within the archive, but not a separate archive itself. I.e. extending class Actor is impossible since it's defined within gzdoom.pk3 archive. Any attempt to extend it in another archive file will result in an error at compile time.

Extending a class allows extra definitions to be added when needed, for ease of organization.

extend class MyClass
    // Insert new functions, variables, or the likes here.

See also