[SOLVED] ESM Scripts attribute type documentation issues

Hi,

I wanted to write scripts in the now recommended ESM format for newly written scripts for the first time today and wondered, why the parameters in some of my scripts are not listed in the editor. While digging into the issue I tried to follow the examples in the documentation closely without success.

Finally I found out that in the description of the Attribute types the general JavaScript types “number", “string" and “boolean" need to be written with capital first letters as “Number", “String" and “Boolean”. Please update the documentation.

And I found out that the attributes Vec2 , Vec3 , Vec4 , Entity , Asset or Color can’t just be written as strings in the editor. The type declarations are PlayCanvas types and need to be imported into the script first before they can be used. It would be very helpful to clearly note in the documentation that the PlayCanvas types need to be imported and to extend the documentation with code examples like the following to remind people new to PlayCanvas coding, that certain types need to be imported:

import { Asset } from 'playcanvas’;

...

/**
 * @attribute
 * @type {Asset}
 */
myTexture;

And please correct the documentation for Attributes:

import { Color, Script } from 'playcanvas';

export class Configurable extends Script {
    /** @attribute */
    speed = 5;
    
    /** @attribute */
    color = new Color(1, 0, 0);
    
    /** 
     * @attribute 
     * @type {Entity}
     */
    target;
}

must be

import { Color, Script, Entity } from 'playcanvas';

export class Configurable extends Script {
    /** @attribute */
    speed = 5;
    
    /** @attribute */
    color = new Color(1, 0, 0);
    
    /** 
     * @attribute 
     * @type {Entity}
     */
    target;
}

Thanks for pointing this out. I have fixed the second issue here:

This is now deployed. Next, we’ll fix this in the script attributes guide for ESM…

cc @Mark_Lundin

:+1:

1 Like

OK, I’ve fixed the other problem too now. Each subsection for attribute types have a note to import the corresponding type from the playcanvas engine.

I’ve fixed a large amount of code formatting problems too! :tada:

:100:

2 Likes