This site requires JavaScript, please enable it in your browser!
Greenfoot back
HTown_Diva
HTown_Diva wrote ...

2015/4/30

Code Won't Compile - Fresh Eyes Needed

HTown_Diva HTown_Diva

2015/4/30

#
I can't get this code to compile. What am I not seeing?
 public void act() 
    {
        // Add your action code here.
    }  
    public void moveArrowKeys()
    {// start method
        // See if any keys are down
        if (Greenfoot.isKeyDown("up"))
        {
            // Move UP one position
            setRotation(270);
            setImage("cat-walk-right.png");
            move(5);
            Greenfoot.delay(5);
            setImage("cat-walk-right-2.png");
            move(5);
            Greenfoot.delay(5);
        }
        else if (Greenfoot.isKeyDown("down"))
        {
            // Move DOWN one position
            setRotation(90);
            setImage("cat-walk-right.png");
            move(5);
            Greenfoot.delay(5);
            setImage("cat-walk-right-2.png");
            move(5);
            Greenfoot.delay(5);
        }
        else if (Greenfoot.isKeyDown("right"))
        {
            // Move RIGHT one position
            setRotation(0);
            setImage("cat-walk-right.png");
            move(5);
            Greenfoot.delay(5);
            setImage("cat-walk-right-2.png");
            move(5);
            Greenfoot.delay(5);
        }
        else if (Greenfoot.isKeyDown("left"))
        {
            // Move LEFT one position
            setRotation(0);
            setImage("cat-walk-right.png");
            move(-5);
            Greenfoot.delay(5);
            setImage("cat-walk-right-2.png");
            move(-5);
            Greenfoot.delay(5);
        }
    }// end method 
}
Super_Hippo Super_Hippo

2015/4/30

#
It would be much easier if you would show the error message and tell us where it occurs.
HTown_Diva HTown_Diva

2015/4/30

#
That's the problem no error message is given, it just won't compile.
davmac davmac

2015/4/30

#
That's the problem no error message is given, it just won't compile.
What do you mean by "compile"? If there's no error message, the compile was successful. It might not do what you want, however. In this case, your act() method does nothing. You have a moveArrowKeys() method, but it is never called. Perhaps you meant to call the moveArrowKeys() method from your act() method?
HTown_Diva HTown_Diva

2015/5/1

#
davmac the code was input straight from what my teacher gave us. Once I enter the code listed, I hit compile and it just clocks meaning something is not right in the code, but I can't see what.
danpost danpost

2015/5/1

#
What do you mean by "it just clocks"? Can you be more specific (or descriptive) as to what is happening?
HTown_Diva HTown_Diva

2015/5/1

#
Nothing happens what I press compile. Compiling just shows at the bottom. After about five minutes I have to do a Ctrl - Alt -Delete to end the task and reopen it up to see what code is causing it not to compile. I wish i could send you a screen shot.
Super_Hippo Super_Hippo

2015/5/1

#
How does the constructor of the world look like?
You need to login to post a reply.