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

2014/12/22

cant call method from an other class

ds06 ds06

2014/12/22

#
Hello, can someone explain to me how i can call a method from an other class? i tried it like this: World:
public class Level1 extends World
{
   
    public Actor Held = new Player();
public Level1()
    {   
addObject(Held, 110, 336);
}
Player:
public boolean getSchlaegt(){
        return schlaegt;
    }
and in my Gegner class i try to call getSchlaegt():
 Actor g=((Level1)getWorld()).Held;
        boolean a = g.getSchlaegt();
What is wrong?
fejfo fejfo

2014/12/22

#
I think all u need to do to call getSchlaegt(); is
Player.getSchlaegt();
or
nameOfYourPlayerObject.getSchlaegt();
danpost danpost

2014/12/22

#
The problem is that the field is of Actor type and not of Player type. The compiler does not know to look in the Player class for the field.
You need to login to post a reply.