Mod:Creation Kit/Struct Reference

Structs are basically mini-objects that can hold several variables of different types, but cannot contain functions or events, and cannot extend any objects or other structs. However, like objects (and unlike structs in other languages) they are passed and held onto by reference, not by value. Structs may be used in arrays.

Defining a Struct
+             'endstruct'

A struct is defined by having its name on the line with the struct, followed by the list of variables the struct contains, and terminated with 'endStruct'. The variables inside a struct can be anything except another struct, an array, or a var. Struct variables also may not be defined as const. Unlike object variables, struct variables may have documentation strings attached.

Examples
struct Point float X float Y endStruct struct QuestStage Quest QuestToSet {The quest whose stage is to be set} int StageToSet {The stage to set on the quest} endStruct struct BadStruct Var MyVariable ; BAD - cannot contain var type variables int[] MyArray ; BAD - cannot contain arrays Point MyPoint ; BAD - cannot contain other structs float MyFloat const ; BAD - cannot have const variables endStruct
 * A struct containing two floats
 * A struct containing a quest and a stage to set
 * A struct that will FAIL to compile

Struct Creation


To create a struct, use the "new" keyword, followed by the type.

The initial value of each variable in the struct will be the default value specified for each member in the struct definition.

If you make a struct property, then the Creation Kit will create and set up the struct for you if the CK user gives it a value.

Note that this cannot appear in the script outside of a function.

Examples
Point myPoint = new Point Point[] array = new Point[5] array[0] = new Point array[1] = new Point array[2] = new Point array[3] = new Point array[4] = new Point
 * Create a new point structure.
 * Create an array of five new point structures.

Accessing Struct Types in Other Scripts


You can access a struct type defined in another script by prefixing the name of the struct with the name of the script containing the struct, separating them with a colon. If you don't want to type in the script name all the type, you can use Import, just like with global functions.

Examples
MyScript:Point myPoint = new MyScript:Point
 * Assume Point struct is defined in MyScript

Struct Members


To get a specific struct member, put its name after a dot, just like accessing a property on a script.

Examples
x = myPoint.X myQuestStage.QuestToSet.SetStage(myQuestStage.StageToSet)
 * get X element of a point
 * Set the quest stage contained in the "questStage" struct defined above