admin管理员组

文章数量:1355570

Trying to create an actor class for an html5 game, but I get an Uncaught SyntaxError. Not sure at all what it means or how to fix it. Other questions like this are usually about Jquery and I couldn't find any solutions that fit my problem.

    function Actor(x, y){
//...
        this.direction = 270;
//...
    }


    Actor.prototype.update = function(){
        if(this.speed >= this.maxspeed)
            this.speed = this.maxspeed;

            if(Key.isDown(Key.getCode("a")) this.direction -= 1; // < -- ERROR OCCURS HERE
            if(Key.isDown(Key.getCode("d")) this.direction +=1;
            if(Key.isDown(Key.getCode(" ") this.move();
     }

Trying to create an actor class for an html5 game, but I get an Uncaught SyntaxError. Not sure at all what it means or how to fix it. Other questions like this are usually about Jquery and I couldn't find any solutions that fit my problem.

    function Actor(x, y){
//...
        this.direction = 270;
//...
    }


    Actor.prototype.update = function(){
        if(this.speed >= this.maxspeed)
            this.speed = this.maxspeed;

            if(Key.isDown(Key.getCode("a")) this.direction -= 1; // < -- ERROR OCCURS HERE
            if(Key.isDown(Key.getCode("d")) this.direction +=1;
            if(Key.isDown(Key.getCode(" ") this.move();
     }
Share Improve this question asked Aug 13, 2013 at 21:46 jatmdmjatmdm 751 gold badge1 silver badge5 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 4

You're missing a closing parentheses in all your if statements. They should be

if(Key.isDown(Key.getCode("a"))) this.direction -= 1;
if(Key.isDown(Key.getCode("d"))) this.direction +=1;
if(Key.isDown(Key.getCode(" "))) this.move();
if(Key.isDown(Key.getCode("a")) this.direction -= 1;

You have 3 opening parens, and only 2 closing ones.

if(Key.isDown(Key.getCode("a"))) this.direction -= 1;
//                             ^ added

You have multiple lines with this same problem. Correct them all.

本文标签: javascriptUncaught SyntaxError Unexpected token this Javasctript ErrorStack Overflow