Structs

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.

Note: This feature is for ZScript only.

Limitations

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';
}

Examples

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

This article is issued from Zdoom. The text is licensed under Creative Commons - Attribution - Sharealike. Additional terms may apply for the media files.