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

Structs behave similarly to their C++ versions. They are defined in the global space outside of a class and declared inside of actors, capable of holding functions and variables of any type. These are useful for passing large amounts of data around, or for doing external bookkeeping on existing classes.


Structs currently cannot be returned, nor can they be passed normally. They must be passed by reference.

Using the special word out in a function will enable anything with that qualifier being sent into the function to be sent only as a reference, which can then be modified.

Furthermore, structs cannot be used with arrays. If returning or using an array is needed, a class should be used instead.

void CheckStruct(out SpecialConstants s)
    // Perform modifications to the SpecialConstants struct 's' here.
    s.somename = 'Zombieman';


This is an example of defining a struct of constants and using them in actor classes.

struct SpecialConstants
  Class<Actor> somename;
  const Target = AAPTR_TARGET;
  const Master = AAPTR_MASTER;
  const Tracer = AAPTR_TRACER;
  enum MyEnum
     num1 = 1,
     num2 = 2,
     num3, // Auto-assigned the next incremented value. In this case, 3.
     num4, // Auto-assigned the next incremented value. In this case, 4.

class Monstah : Actor
     TNT1 A 0
        SpecialConstants cns;
        cns.somename = "ItemToken"; // Assuming this is a valid item, mind.
        if (CountInv(cns.somename,cns.Target) == cns.num2)
           //Do something

Native structs

See also