From ZDoom Wiki
Jump to: navigation, 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.

Passing Structs

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.

void CheckStruct(out SpecialConstants s)
    // Structs cannot be returned, but they can be read/modified.
    // Copying a struct currently must be done manually, so consider
    // using a regular class or object instead if possible.


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