Adding materials to a script

I’m now reading the tutorials and I’m trying to understand the basic mouse input one.
I pasted the mouse.js code into the script of my test project after I created the different materials, but I don’t know how to refer those materials to my script.
What I discovered is that after I pasted the mouse.js code into the mouse.js script of my first box, if I create a second box and add a script to it with the same name (mouse.js), I’m asked what materials I want to refer to the script.

What you’re seeing the Script Attributes.

The line:

pc.script.attribute("materials", "asset", [], {type: "material"});

Declares that this script can reference material assets. If you set the materials in the Editor you can then access them in your code*:

var asset = context.assets.getAssetById(this.materials[0]);
var material = asset.resource;

*I’ve just noticed the code on this page is a little out of date, getAssetByResourceId is now getAssetById

When you add a new script attribute you need to refresh them in the editor to get them to appear. You can do this in the Entity Menu -> Refresh Script Attributes.

I missed that Entity Menu -> Refresh Script Attributes. I was looking for it through the right mouse click only.