GMLscripts.com

instance_singleton

Returns a single instance of the given object, creating one if no instance exists.

A = instance_singleton(object, "Instances");  //  An instance of object is created.
B = instance_singleton(object, "Instances");  //  The first instance is returned; A and B are equal.
instance_singleton(object, layer_id)
Returns a single instance of the given object, creating one if no instance exists.
COPY/// @func   instance_singleton(object, layer_id)
///
/// @desc   Returns a single instance of the given object,
///         creating one if no instance exists.
///
/// @param  {object}    object      object to look for
/// @param  {layer}     layer_id    layer to create in
///
/// @return {instance}  object instance id
///
/// GMLscripts.com/license

function instance_singleton(object, layer_id)
{
    if (instance_number(object) == 0) {
        return instance_create_layer(0, 0, layer_id, object);
    }
    return instance_find(object, 0);
}

Contributors: RaniSputnik

GitHub: View · Commits · Blame · Raw