Skip to main content

The "ds_struct_find_index" Function

Syntax#

ds_struct_find_index(id, key);
ArgumentTypeDescription
idstructThe struct to check
keystringThe key (i.e. struct content) to check index of

Description#

Checks if a variable name (as a string) exists within the given struct and returns the index of the parent struct. The result can then be used with standard struct accessors (see official GameMaker documentation for details). Naturally, this is primarily useful for checking recursively, including any structs-within-structs.

If multiple levels of struct exist, it is possible for the same key to occur multiple times with different values. To increase the speed and precision of this function, you can specify which level to search by prepending the key with any parent structs separated by a period. In this case, the first parent specified must exist in the root struct, but deeper levels will be recursed and are optional.

If the specified key doesn't exist, -1 will be returned instead. To detect whether the key exists first, use ds_struct_exists.

Example#

var struct_text = ds_struct_find_index(my_struct, "font");
draw_set_font(struct_text.font);
draw_set_color(struct_text.color);