Official function to create an instance

Official function to create an instance, see system.js, line 1284.

SysActs.prototype.CreateObject = function (obj, layer, x, y)
{
    if (!layer || !obj)
        return;

    var inst = this.runtime.createInstance(obj, layer, x, y);
 
    if (!inst)
        return;
 
    this.runtime.isInOnDestroy++;
 
    var i, len, s;
    this.runtime.trigger(Object.getPrototypeOf(obj.plugin).cnds.OnCreated, inst);
 
    if (inst.is_contained)
    {
        for (i = 0, len = inst.siblings.length; i < len; i++)
        {
            s = inst.siblings[i];
            this.runtime.trigger(Object.getPrototypeOf(s.type.plugin).cnds.OnCreated, s);
        }
    }
 
    this.runtime.isInOnDestroy--;

    // Pick just this instance
    var sol = obj.getCurrentSol();
    sol.select_all = false;
    sol.instances.length = 1;
    sol.instances[0] = inst;
 
    // Siblings aren't in instance lists yet, pick them manually
    if (inst.is_contained)
    {
        for (i = 0, len = inst.siblings.length; i < len; i++)
        {
            s = inst.siblings[i];
            sol = s.type.getCurrentSol();
            sol.select_all = false;
            sol.instances.length = 1;
            sol.instances[0] = s;
        }
    }
};