variable_struct_get_names

This function returns an array with the variable names from a struct.

You pass in the struct reference to check, and each entry in the array will be a String of the variable names that the struct contains.

 

Syntax:

variable_struct_get_names(struct);

Argument Type Description
struct Struct The struct reference to check.

 

Returns:

Array (each entry is a String)

 

Example:

var _my_struct = {a: 7, str: "a string"};

var _arr_names = variable_struct_get_names(_my_struct);
show_debug_message("Variables for struct: " + string(_arr_names));

var _str = "", _len = array_length(_arr_names);
for (var i = 0; i < _len; i++;)
{
    _str = _arr_names[i] + ":" + string(struct_get(_my_struct, _arr_names[i]));
    show_debug_message(_str);
}

The above code first creates a temporary struct variable _my_struct with two variables in it: a and str. Next, variable_struct_get_names is called to get an array with the variable names for the given struct. These are displayed. Finally, a for loop is used to loop through all the variable names in the array and to look up the corresponding value in the struct by name using variable_struct_get. For each of these key-value pairs, a debug message is shown using show_debug_message.