Issue swapping out entities

Hi,

I have become stuck with a function I want to make.

I have 3 entities each containing multiple lights.

I used the model swap tutorial to work well with swapping out objects, but wanted to extend that to hide and show entities. I want to show an initial entity (a) then show others on key presses as shown below but I’m a little stuck how to do this?

var Updatelights = pc.createScript('updatelights');


Updatelights.attributes.add('a', {
    type: 'entity',
    assetType: 'entity'
});

Updatelights.attributes.add('b', {
    type: 'entity',
    assetType: 'entity'
});

Updatelights.attributes.add('c', {
    type: 'entity',
    assetType: 'entity'
});

Updatelights.prototype.initialize = function() {
    this.app.keyboard.preventDefault = true;
};


// update code called every frame
Updatelights.prototype.update = function(dt) {
    var app = this.app;
    
    if (app.keyboard.isPressed(pc.KEY_Z)) {
        if (this.entity.entity.entity !== this.b.resource) {
            // update the model component to the new model
            this.entity.entity.entity = this.b.resource;
        }
    } else {
        if (this.entity.entity.entity !== this.a.resource) {
            // restore original model
            this.entity.entity.entity = this.a.resource;    
        }

        if (app.keyboard.isPressed(pc.KEY_X)) {
           if (this.entity.entity.entity !== this.c.resource) {
            // update the model component to the new model
            this.entity.entity.entity = this.c.resource;
        }
    } else {
        if (this.entity.entity.entity !== this.a.resource) {
            // restore original model
            this.entity.entity.entity = this.a.resource;    
        }
    }

    } 

    // clear

    if (app.keyboard.isPressed(pc.KEY_C)) {
        app.assets.load(this.c);
    }
};

The problem you have here is with this:
this.entity.entity.entity - that is something completely unnecessary.
And entity type attribute is not an asset, so no need of .resource.

Please use debugging in particular breakpoints to stop execution around keypress conditions, to inspect variables you are trying to compare, it will give you a good idea what is what:

http://developer.playcanvas.com/en/user-manual/scripting/debugging/