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

2015/4/22

Not a statement error

LuminescentNebula LuminescentNebula

2015/4/22

#
I'm trying to animate my crab in the code, but when I try to define the images it says "not a statement"
public class Crab extends Actor
{
   private GreenfootImage image1;
private GreenfootImage image2;
public Crab()
{
     image 1 = new GreenfootImage("crab.png");
     image 2 = new GreenfootImage(“crab2.png”);
    setImage(image1);
    if ( getImage() == image1 )
    {
        setImage(image2);
    }
    else
    {
        setImage(image1);
    }
does anyone know where the mistake is, and how to fix it?
danpost danpost

2015/4/22

#
I see several problems with the code you posted: * lines 7 and 8 have inserted spaces in the image field names (they should be 'image1' and 'image2', without the spaces) * line 8 appears to have the wrong type double quotes around the string (it is not showing in blue like in the previous line) * lines 10 on should not be in the constructor, but in the act method of the class
LuminescentNebula LuminescentNebula

2015/4/22

#
Alright, I got it. It works now. Thank you so much!
You need to login to post a reply.