Error message "error loading scripts, open browser console for details"

I have a simple program that I am running, it is the start of a larger project, but when I open the launcher I get the error message “error loading scripts, open browser console for details”. I have used this same script before with no problems, and this only happened after I made some additions and then later removed them. Here is my script:

pc.script.create('avatar', function (app) {
    var Avatar = function (entity) {    
    
        
    {
        this.entity = entity;
    }


    Avatar.prototype = {
        // Called once after all resources are loaded and before the first update
        initialize: function (Avatar) {
            function stats(Health,Oxygen,Battery) {
            this.Health = 100;
            this.Oxygen = 100;
            this.Battery = 100;
    }
            
        },

        // Called every frame, dt is time in seconds since last update
        update: function (dt) {
            
            var keyboard = new pc.Keyboard(window);
            
            if (app.keyboard.isPressed(pc.KEY_W)){
                this.entity.translate(0, 0, 0.1);
            } else if (app.keyboard.isPressed(pc.KEY_S)){
                this.entity.translate(0, 0, -0.1);
            } else if (app.keyboard.isPressed(pc.KEY_D)){
                this.entity.translate(0.1, 0, 0);
            } else if (app.keyboard.isPressed(pc.KEY_A)){
                this.entity.translate(-0.1, 0, 0);
            } else if (app.keyboard.isPressed(pc.KEY_SPACE)){
                this.entity.translate(0,0.2,0);
            }
               
        }
    };
            
  };
      
});

This script has some obvious issues - one is you are declaring a function called stats inside your initialize method which basically does nothing as this function won’t be visible anywhere outside the initialize method. The other is you are creating a new pc.Keyboard every frame in the update method! You don’t need to do that the app should already have a keyboard property.

Other than that you’ll have to give a link to your project or post a full stack trace from your browser console in order to identify the exact error.

Here’s the link:

https://playcanvas.com/project/383140/overview/futuristic

I know that my error is with the first line, because I checked it on my other computer (the one I am using right now is school regulated so I can’t identify the error through the browser console right now) and something about the name of the script or whatever but I have no idea what the problem there is.

You have mixed scripts notations, you have legacy scripts mixed with scripts 2.0 system. You should choose only one, and based on project, you should use legacy only.

Ok, so what parts of my script are the old notation and what should I change them to?

Check documentation on scripts: http://developer.playcanvas.com/en/user-manual/scripting/
And then check your script files about that.

I am trying that, I can’t see any problems with my code but it still isn’t working

I don’t know if I should trust the documentation, when I open a new script the formatting is different from what the documentation says

As you are using the Legacy scripting system, you need to look at the Legacy sub section found here: http://developer.playcanvas.com/en/user-manual/scripting/legacy/

https://playcanvas.com/editor/code/383140/avatar.js - this file is wrong, and not following correct script definition notation.
https://playcanvas.com/editor/code/383140/Animation.js - this file uses new system, but your project uses legacy system.

Do not rush. Start slow, from simple tutorials one by one on relevant topics: http://developer.playcanvas.com/en/tutorials/
And learn JS steadily as well, I recommend CodeAcademy: https://www.codecademy.com/learn/learn-javascript

Development and gamedev it self - is not easy job, you have to be able to learn and solve problems on your own, and deal with unknowns steadily.

im stuck with the same thing please help

im getting errer with movement

A post was split to a new topic: Trouble with script

3 posts were split to a new topic: Getting ‘error loading scripts’ when launching the game