Structures - hpgDesigns/hpgdesigns-dev.io GitHub Wiki

In C++ and by inheritance, EDL, Structures and Classes are syntactical devices allowing the programmer to group and order related fields in memory. Structures can contain multiple variables, but be instantiated like any other type.

For example, if the programmer wished to store information about an item, such as its x/y coordinate and its name and sprite, a structure could be defined to manage that information like so:

struct item {
  string name; // Name of this item that will be displayed to users on encounter
  double x, y; // The coordinates of this item in the room
  int sprite;  // The sprite to be drawn for this item

  // An example of a member function for conveniently updating both x and y
  void moveTo(double newX, double newY) { x = newX; y = newY; }
};

An item can then be allocated using the dark art that is C++ until we automate it better in EDL.

It is important to realize that structures and classes cannot be defined in EDL as with other code. They must be defined in Definitions, as with other C++ functions. Then they can be instantiated and used in your EDL code. In other words, the above example code could not be placed in, say, an object's Create event. It must go in Definitions.

Struct vs Class

struct and class are virtually synonymous. The distinction is that classes default private, whereas struct implies public.