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

2022/12/11

Accessing an actor's boolean in the world

I need a way to count how often a target has been hit by a bullet. This code is in the bullet class:
public boolean hit()
    {
        if(isTouching(Feind1.class))
        {
            return true;
        }
    }
This is the code in my world which should transfer the information of a bullet hit to increasing the "treffer" counter. However I get the error message: "Undeclared method: hit()".
Actor bullet = (bullet) getObjects(bullet.class).get(0);
        if (bullet != null)
        {
            if (bullet.hit())
            {
                treffer++;
            }
        }
Help of any kind would be greatly appreciated!
Spock47 Spock47

2022/12/12

#
Change line
Actor bullet = (bullet) getObjects(bullet.class).get(0);
to
bullet bullet = (bullet)getObjects(bullet.class).get(0);
You need to login to post a reply.