Skip to main content

The "is_empty" Function

Syntax#

is_empty(val);
ArgumentTypeDescription
valanyA variable/value to check

Description#

Checks if a given value is "empty", which can be true or false depending on the type of data contained in the input value.

Some examples of "empty" data include:

  • undefined
  • NaN
  • false
  • 0
  • "0"
  • ""
  • []
  • {}
  • etc.

If the input value points to a data structure, buffer, etc., the structure will be considered empty if no values exist inside the structure itself. Transparent surfaces are also considered empty.

Some types of data cannot be evaluated and will return false by default. Also note that different data types incur different performance costs to evaluate.

caution

Note that in some cases this function may not return the expected result due to the way GameMaker handles pointers. This means some types of data can share the same value, and whichever one happens to be first will take priority.

Example#

var surf = surface_create(1280, 720);
var ds = ds_list_create();
if (is_empty(surf)) {
surface_copy(surf, 0, 0, application_surface);
}
if (is_empty(ds)) {
ds_list_add(ds, surf);
}