Skip to main content

The "ds_struct_equals" Function

Syntax#

ds_struct_equals(var1, var2);
ArgumentTypeDescription
var1structThe source struct to be compared
var2structThe target struct to compare with

Description#

Compares the contents of two structs and returns true or false depending on whether the contents and their values are equal. This script will function recursively, also comparing any structs and arrays within the root struct.

Note that volatile data structure and method contents cannot be compared due to GameMaker's handling of references for these types, and as such may behave differently than expected:

  • Data structures will be compared by reference only and thus will only return true if the exact same structure is referenced. Identical copies will return false because each copy has a unique (non-matching) index.
  • Methods cannot be compared by contents or reference and therefore will always return true provided a method exists at the same location in each struct.

Example#

var struct1 = { name: "John Doe", age: 30 };
var struct2 = { age: 30, name: "John Doe" };
if (ds_struct_equals(struct1, struct2)) {
show_message("Structs are equal!");
}