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

2019/6/26

Cannot find symbol- variable Player

MisterUnknown MisterUnknown

2019/6/26

#
 shootKey = this.Player.playerNum == 0 ? "e": "o";
My code has problems with Player and always gives me the same errors three times in the pipe-class, which I have declared inside the player-class. I hope someone finds a way to fix the errors Thanks in advance :)
public class Pipe extends Actor 
{
    String shootKey;
    int shotCoolDown = 0;
     
   
    
    
    public Pipe()
    {
        
        shootKey = this.Player.playerNum == 0 ? "e": "o";
       GreenfootImage img = new GreenfootImage("Rohr"+(this.Player.playerNum+1)+".PNG");
      img.scale(25, 25);
      setImage(img);
    }

public void act()
{
   if (this.Player.getWorld() == null) { getWorld().removeObject(this); return; }
    shootStuff();
    
}
public void shootStuff()
{
   if (shotCoolDown > 0) shotCoolDown--;
  else if (Greenfoot.isKeyDown(shootKey))
  {
        getWorld().addObject(new Bullet(getRotation()), getX(), getY());
      shotCoolDown = 20;
 }
}
}
danpost danpost

2019/6/26

#
MisterUnknown wrote...
My code has problems with Player and always gives me the same errors three times in the pipe-class, which I have declared inside the player-class.
Sorry -- I got it backward. Change all this.Player to Player.this.
You need to login to post a reply.