User:Sunjammer/Struct keyword (draft)

From Dragon Age Toolset Wiki
Jump to: navigation, search

The struct keyword is used to construct a composite data type, or structure, consisting of a set related members/variables/values which can be accessed individually using the dot operator.

The vector data type is a predefined struct which consists of three values: x, y and z. To access or modify the y value of a vector, v, we would use v.y for example v.y = 1.2.

struct name
{
    type identifier1;
    type identifier2,identifier3;
    type identifier4;
};

Things to note: braces, semi-colon after member declaration, semi-colon after struct declaration.

Remarks

  • you cannot nest structs
  • you can include the command, effect, event, float, int, location, object or string data types and they all appear to work
  • you can include the itemproperty data type however there is no point (it is not used by anything other than its Get/SetLocal functions)
  • you can include the vector data type or another struct but it will either fail to compile (can generate a "Void expression where non void required" error) or fail at runtime when you try to access it/its members
  • you cannot include the resource data type: it will not compile (generates a "Bad type specifier" error)
  • you cannot include an array (can generate an "Incorrect variable state left on stack" or "Void expression where non void required" error)
  • you cannot declare an array of structs


  • wrapping a vector in a dummy location
  • wrapping a resource in a dummy event
  • a pseudo-array could be created using an effect (limited to floats, ints, objects and/or strings)
  • a pseudo-array could be created using an event (limited to floats, ints, locations, objects, resources and/or strings)

Examples

// user-defined type
struct quaternion
{
    float w, x, y, z;
};
 
// constructor
struct quaternion Quaternion(float fW, float fX, float fY, float fZ)
{
    struct quaternion q;
 
    q.w = fW;
    q.x = fX;
    q.y = fY;
    q.z = fZ;
 
    return q;
}
 
void main()
{
    struct quaternion q = Quaternion(0.0, 0.0, 0.0, 0.0);
}
  • Declaration
  • Definition
  • Assignment
  • Comparison
  • Member access
  • Passing into a function
  • Returning from a function

See Also