pc.registerScript problem

Hi guys,I am facing a problem when I try to register scripts by pc.registerScript().I try to refer an entity which I set in editor,but the result is not correct,here is my code:
image

image

The example project can be found here: demo

Can anyone give me some advice?

This is interesting. Looks like by adding a property, it stops whatever logic we have in the engine that converts the GUID (which is what is stored in the scene data) into a the actual Entity object

So the issue is here:

Because the property box is already defined in RegisterScript1, it doesn’t create the hook ups and event listeners for the attribute to convert it from a GUID to Entity.

At the moment, we don’t have an recommended practises for using ES6 classes but something I’m thinking about.

1 Like

Thanks @yaustar ,I hope we can find a good solution since ES6 classes is pretty common now :smiley:

I was trying last week to use JS Docs to help the autocomplete know about the script attribute with no success.

The closest I got was this which was clumsy:

Code where I assigned a variable to itself

class Test extends pc.ScriptType {     

    initialize() {
        /** @type {string} */
        this.foobar2 = this.foobar2;
        this.testName = 'testName2';
        console.log(this.testName);
    }

    postInitialize() {
        console.log(this.testFunction());
        console.log(this.foobar2);
    }

    testFunction () {
        return 'someOtherString';
    }
}

pc.registerScript(Test, 'test');

Test.attributes.add('foobar2', {type: 'string'});

Maybe @LeXXik has some good ideas here?

1 Like

Yeah, I have an idea - don’t use class properties in ScriptTypes :slight_smile:

Edit:
I wasn’t able to use them in the past, but I didn’t spend much time on researching the issue, either. I simply don’t use them.

2 Likes