What is the secret to getting a script to preload?

I believe that I am trying to get the asset into the Asset Registry so that it can be added to an entity. However when I create a new script, it appears with a dot in front of it and cannot be added to an entity.

Unloaded assets

It might be that I am still having legacy vs 2.0 problems. Not sure because I haven’t figured out how to correctly convert files to the new system.

Here is the script.

var Collider = pc.createScript(‘collider’);

// initialize code called once per entity
Collider.prototype.initialize = function () {
this.entity.collision.on(‘collisionstart’, this.onCollisionStart, this);
};

Collision.prototype.update = function(dt) {

Collision.prototype.onCollisionStart = function(result){
if(result.other.rigidbody){
this.entity.destroy();
}
};
};

Can you share the project please?

https://playcanvas.com/editor/scene/581458

Collider.js

var Collider = pc.createScript('collider');


// initialize code called once per entity
Collider.prototype.initialize = function () {
        this.entity.collision.on('collisionstart', this.onCollisionStart, this);
};

    Collision.prototype.update = function(dt) {
        if(result.other.rigidbody)
        this.entity.destroy();
};

When you click on ‘parse’ in the editor, it comes up with the error:
image

In the code, you’ve created a script object called Collider but used Collision for the update function prototype.

You also now have move.js and movement.js` which look exactly the same in terms of code.

Gotcha. I fixed that. The script still doesn’t work though. It does attach to the entity but when the player bumps into a wall, it doesn’t get destroyed.

I’m still confused why when I create a script by going to assets and clicking on the + sign it creates a script with a dot in front of it. And a script with a dot in front of it won’t attach to an entity.

If I add a script component in the entity and then choose + New Script, I can attach a script that way. Is this a bug or am I doing something wrong when I just try to add scripts directly to the library?

A script with as dot means that script hasn’t been attached to an entity yet. AKA the editor doesn’t think it has been used.

If you can’t attach that script, it means you have an error or issue in that script and until that error is fixed, you can’t attach that script.

That makes sense regarding the dot.

Can you tell me why the script doesn’t make the entity disappear?

I’m looking at the scripts now and there’s no logic written to make anything disappear? Have you removed some code in the last few hours?