Vector keyword

From Dragon Age Toolset Wiki
Jump to: navigation, search

The vector type represents a position or direction in three dimensions. It consists of three float values representing x, y and z which are accessed using the "dot operator". The default value is (0.0, 0.0, 0.0).


The constructor for a vector is the Vector function.


A vector literal consists of one to three float values separated by commas and enclosed in square brackets.

    // valid vector literals
    vector vLiteral1 = [1.0];
    vector vLiteral2 = [1.0, 2.0];
    vector vLiteral3 = [1.0, 2.0, 3.0];
    // invalid vector literals
    vector vInvalid1 = [1.0, , 3.0];    // causes "Parsing constant vector" error
    vector vInvalid2 = [1.0, 2, 3.0];   // causes "Parsing constant vector" error
    vector vInvalid3 = 1.0, 2.0, 3.0;   // causes "Parsing variable list" error
    vector vInvalid4 = (1.0, 2.0, 3.0); // causes "Unknown state in compiler" error

Note although there is a literal, a vector cannot be declared as a constant using the const keyword.



The following functions can be used to convert another data type to a vector:

The following functions can be used to convert a vector to another data type:


There is no implicit conversion to a vector.


There are no native functions providing persistence for a vector, however derived functions can be created using GetLocalFloat and SetLocalFloat to store and retrieve the individual components.

// Gets three floating point variables from the specified object and returns them as a vector.
vector GetLocalVector(object oObject, string sVarName)
    float fX = GetLocalFloat(oObject, sVarName + "x");
    float fY = GetLocalFloat(oObject, sVarName + "y");
    float fZ = GetLocalFloat(oObject, sVarName + "z");
    return Vector(fX, fY, fZ);
// Sets three floating point variables, representing a vector, on the specified object.
void SetLocalVector(object oObject, string sVarName, vector vValue)
    SetLocalFloat(oObject, sVarName + "x", vValue.x);
    SetLocalFloat(oObject, sVarName + "y", vValue.y);
    SetLocalFloat(oObject, sVarName + "z", vValue.z);

As with all Get|SetLocal* functions the name of the variable must be predefined in the object's variables 2da file. In this instance all three variables (with the appropriate suffix) must be predefined.


void main()
    // uninitialised: value = (0.0, 0.0, 0.0)
    vector vDefault;
    // initialised using a literal: value = (1.0, 2.0, 3.0)
    vector vSpecific = [1.0, 2.0, 3.0];
    // initialised using the constructor: value = (1.0, 2.0, 3.0)
    vector vConstructed = Vector(1.0, 2.0, 3.0);
    // initialised using a function: value = (-1.0, 0.0, 0.0)
    vector vConverted = AngleToVector(90.0);    

See Also

Vector functions