Structs

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.

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
{
  //...
  States
  {
  Missile:
     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