-
Notifications
You must be signed in to change notification settings - Fork 2
Interacting with game objects
Important
You are viewing documentation for C#.
To view the C++ article, click here.
In C#, there are 4 main types of managed objects you may encounter. Each one corresponds to a native GameMaker type. The mapping can be seen in the table below:
| C# type | C++ Type | Description |
|---|---|---|
GameVariable |
RValue |
Describes a GameMaker variable. |
GameObject |
YYObjectBase |
Describes a generic struct, sequence, instance or accessor object. |
GameInstance |
CInstance |
Describes an instance of a GameMaker object. |
GameRoom |
CRoom |
Describes a room. |
This is the all-encapsulating type of GameMaker, similar to the C# object. It can contain any data supported by GameMaker itself - this means that one GameVariable object might contain a number, while another contains a string, all under the same type.
Being essentially just a boxed type, GameVariable can be instantiated from many C# types. It can then be implicitely converted back into those types.
If the conversion is invalid (such as trying to convert a string variable to a C# int, an InvalidCastException is thrown.
This also holds true for all of the To* conversion functions.
If a GameVariable isn't assigned a value, it's initialized as undefined.
In order to check what underlying type a GameVariable holds, code can query the GameVariable.Type property of the target object. This property holds one of the following strings:
| C# native type |
Type property value |
|---|---|
double |
number |
string |
string |
IReadOnlyList<GameVariable> |
array |
long |
ptr, int64
|
| N/A | undefined |
GameObject / GameInstance
|
struct / method
|
bool |
bool |
Some types (such as structs or arrays) cannot have a reference to them outside of GameMaker, as their lifetime is not controlled by the C# runtime. This makes it impossible to obtain a "live" reference to both arrays and structs.
Due to this fact, there is no ToArray() or ToDictionary() function - instead, a read-only view of the contained array is returned by ToArrayView(). To atomically mutate members of an array, use the operator[int] indexer. Similarly to this, structs may have their members enumerated by looking at the Members read-only list of GameObject / GameInstance, but changes will only be reflected when using operator[string]. The same behavior also applies to GameVariable holding a struct.