struct_get

This function gets the value from a given named variable within a struct.

You supply the struct reference as well as the name of the variable to get the value of as a string (see example code below). The function will return the value held by the variable or undefined if the named variable does not exist.

IMPORTANT If the variable you are getting does not exist then the function will return the keyword undefined and you may get errors that will stop the game from functioning, so if in doubt use the function struct_exists first.

 

Syntax:

struct_get(struct, name);

Argument Type Description
struct Struct The struct reference to use
name String The name of the variable to get (as a string)

 

Returns:

Any (any data type) or undefined (if the named variable does not exist)

 

Example:

if struct_exists(mystruct, "shields")
{
    var ss = struct_get(mystruct, "shields");
}
else
{
    var ss = -1;
}

The above code will check to see if a variable exists in the given struct and if it does then the value it holds is retrieved and stored in a local variable. If it does not exist, the local variable is set to -1.