In my game, I've added a counter in no problem to count how much ammo I have left, however, when I try to add a new counter for a separate actor, it says "cannot find symbol- variable redCounter" and I have an actor with the name RedCounter and it has the same code as the normal counter but has been tweaked to compile. Here's the code in the actor which has the problem:
and in comparison I have another code showing an alternate actor with virtually the same code in my game:
Someone help me on why I'm getting this error.
1 2 3 4 5 6 7 8 9 10 11 12 13 | public void shoot() { if (Greenfoot.isKeyDown( "shift" )) { if (redCounter.getValue() > 0 ) { RedShot redShot = new RedShot(); getWorld().addObject(redShot,getX(),getY()); redShot.setRotation(getRotation()); redCounter.add(- 1 ); } } } |
1 2 3 4 5 6 7 8 9 10 11 12 13 | public void shoot() { if (Greenfoot.isKeyDown( "space" )) { if (counter.getValue() > 0 ) { Shot shot = new Shot(); getWorld().addObject(shot,getX(),getY()); shot.setRotation(getRotation()); counter.add(- 1 ); } } } |