Skip to main content

The "ds_struct_exists" Function

Syntax#

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

Description#

Checks if a variable name (as a string) exists within the given struct and returns true or false. Unlike the built-in variable_struct_exists function, this script will check 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.

note

This script is for checking if the contents of a struct exist, not a struct itself.

To get the value of the key, if found, use ds_struct_find_value.

Example#

// Both "font" and "text.font" are acceptable and will return the same value
if (ds_struct_exists(my_struct, "text.font")) {
var my_font = ds_struct_find_value(my_struct, "text.font");
draw_set_font(my_font);
}