BUG: Cannot read property 'index' of undefined in [[playcanvas-stable.js:67608]]

I have a project that cannot “Play” in the editor with the URL like https://launch.playcanvas.com/somenumberhere.

However, I can run it by downloading it through the API.

The error when pressing “Play” is the following. It’s pretty cryptic to me. What am I doing wrong? Many thanks for your help in advance!

[[playcanvas-stable.js:67608]](https://code.playcanvas.com/playcanvas-stable.js): Cannot read property 'index' of undefined

TypeError: Cannot read property 'index' of undefined
at scriptType.__initializeAttributes (https://code.playcanvas.com/playcanvas-stable.js:67608:49)
at ScriptComponent._onInitializeAttributes (https://code.playcanvas.com/playcanvas-stable.js:54849:21)
at ScriptComponentSystem._callComponentMethod (https://code.playcanvas.com/playcanvas-stable.js:55457:49)
at ScriptComponentSystem._onInitialize (https://code.playcanvas.com/playcanvas-stable.js:55464:9)
at Function._helper (https://code.playcanvas.com/playcanvas-stable.js:35496:12)
at Function.initialize (https://code.playcanvas.com/playcanvas-stable.js:35501:9)
at Application.start (https://code.playcanvas.com/playcanvas-stable.js:61619:20)
at https://launch.playcanvas.com/editor/scene/js/launch.js:7379:25
at Application._preloadScripts (https://code.playcanvas.com/playcanvas-stable.js:61372:5)
at https://launch.playcanvas.com/editor/scene/js/launch.js:7362:21

Hi @matthias and welcome,

The launch url you posted doesn’t seem to work, it returns 404.

Usually a launch url contains a number id:

https://launch.playcanvas.com/34095346

Thanks @Leonidas

Yes, it opens a browser window with a number. Since it is a private project, I have not shared the ID here in the public forum. So I‘ve removed the number.

However, I also checked the developer console in Chrome and that didn‘t reveal really any additional information.

Can you add ‘yaustar’ with read permissions and I can have a quick look? It looks like one of your script attributes hasn’t been set correctly.

Thanks @yaustar. You should have access to it now.

Looks like you are using typescript and the scriptTypes defined are causing issues. It looks like attributes aren’t being created somehow. Has something changed recently as it looks like you have been working on this for a while?

For some reason, the __scriptType is referencing a ScormSystem type when it should be of scriptType.

Digging a little deeper into the main.build.js script, isn’t ScriptTypeBase meant to inherit from ScriptType or something?

I’ve found where the problem lies but I don’t know how to fix it as it’s difficult to parse the compiled code.

In the project’s custom createScript there’s a section that overwrites a bunch of properties:

// Add instance properties and methods to prototype
        for (var prop in instance) {
            if (prop === "attributes" || prop === "name" || attributes.includes(prop)) {
                // do nothing
            }
            else {
                script.prototype[prop] = instance[prop]; // @GBANGA: Complier error fix.
            }
        }

This also includes the constructor property which is used when add script instances to entities.

In this particular case, constructor.attributes which can be seen here:

As this is the project’s custom code, it makes it difficult to advise as I assume this is being done for a reason?

I’ve tried doing the same and was unable to run the build locally.

Thanks for looking into it @yaustar. Our initial idea of overloading the ScriptType turned out not future proof.

We had to stop using newer versions that 1.0.22 since the later versions didn’t work. So downloading and linking to https://code.playcanvas.com/playcanvas-1.22.0.min.js then just works fine.

It would be great to enable the feature in the editor to define the version you would like to run the editor and the engine for a specific project.

Or do you have another idea how we could easily continue to use and playtest by pressing > instead of downloading and switching engine JS?

You can point the launch tab to use an older version of the engine: https://developer.playcanvas.com/en/user-manual/scripting/custom_engine/

Eg https://launch.playcanvas.com/1004487?debug=true&use_local_engine=https://code.playcanvas.com/playcanvas-1.22.0.min.js