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.
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.