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

2015/6/1

Identifier expected error - No idea why

nandr31 nandr31

2015/6/1

#
I have started programming my game for a school project. I am getting an error in the game world when trying to pass the rCounter into helicopter. My helicopter code:
public class Helicopter extends Actor
{
    rCounter rCounter;
    dCounter dCounter;
    /**
     * These are the counters that count how many people have been rescued and how many people have died.
     */
    public Helicopter(rCounter rcounter,dCounter dcounter)
    {
        rCounter = rcounter;
        dCounter = dcounter;
    }

    /**
     * Movement for the helicopter.
     */
    public void act() 
    {
        if(Greenfoot.isKeyDown("up"))
        {
            setRotation(90);
            move(-6);
            setRotation(0);
        }
        if(Greenfoot.isKeyDown("down"))
        {
            setRotation(90);
            move(6);
            setRotation(0);
        }
        if(Greenfoot.isKeyDown("left"))
        {
            move(-6);
        }
        if(Greenfoot.isKeyDown("right"))
        {
            move(6);
        }
    }

    /**
     * The resuce person code.
     */
    public void rescuePerson()
    {
        if(isTouching(Person.class) == true)
        {
            rCounter add;
            //Greenfoot.playSound("");
        }
    }

    /**
     * This adds a point to the rescue counter
     */
    public void addR()
    {
        rCounter.addR(1);
    }

    /**
     * Tests to see if the helicopter is touching a person.
     */
    public boolean isTouchingPerson()
    {
        return getIntersectingObjects(Person.class) != (null);
    }

    /**
     * What happens after we win the game.
     */
    public void gameWin()
    {
        // Greenfoot.playSound("");
        Greenfoot.setWorld(new Win());
    }

    /**
     * What happens after we lose the game.
     */
    public void gameLose()
    {
        //Greenfoot.playSound("");
        Greenfoot.setWorld(new Lose());
    }
}
And here's the code for game, it's giving me the error.
public class Game extends World
{
    private rCounter;
    private dCounter;
    /**
     * Constructor for objects of class Game.
     * 
     */
    public Game()
    {    
        // Create a new world with 600x400 cells with a cell size of 1x1 pixels.
        super(600, 400, 1); 
        //prepare the world
        //add items needed by helicopter to the world

        Helicopter myHelicopter = new Helicopter(rCounter,dCounter);
    }

}
Thanks
danpost danpost

2015/6/1

#
Compare lines 3 and 4 of both code posts. The second set of lines has access modifiers and either a type or a name (I cannot be sure which); but the lines are missing one of them.
You need to login to post a reply.