variable_instance_exists

With this function you can check whether an instance scope variable exists or not. You supply the unique instance ID value (which can be found from the Instance Properties in the room editor, or is returned when you call the function instance_create_layer()) as well as the variable name to check for as a string (see example code below). The function will return true if a variable with the given name exists for the instance and false otherwise.

 

Syntax:

variable_instance_exists(instance_id, name);

ArgumentTypeDescription
instance_idObject InstanceThe unique ID value of the instance to check
nameStringThe name of the variable to check for

 

Returns:

Boolean

 

Example:

if (!variable_instance_exists(id, "shields"))
{
    shields = 0;
}

The above code will check to see if the variable called "shields" exists in the instance running the code and if it does not then it is created and initialised to 0.