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

2021/2/23

How to check if there's an object at a specific location

Znarf Znarf

2021/2/23

#
So I'm trying to make a command that just simply checks if there's any object at a specific location.
danpost danpost

2021/2/23

#
Znarf wrote...
So I'm trying to make a command that just simply checks if there's any object at a specific location.
The World class has a getObjectsAt(int, int, java.lang.Class) method.
Znarf Znarf

2021/2/23

#
Could you mabey use it in a code as an example I'm somehow too incapable to do this
danpost danpost

2021/2/24

#
Znarf wrote...
Could you mabey use it in a code as an example I'm somehow too incapable to do this
for (Object obj : getObjectsAt(300, 200, Actor.class))
{
    if (obj instanceof Player)
    {
        // do something -- for example ...
        ((Player) obj).setHealth(100);
    }
}
Znarf Znarf

2021/2/27

#
So I got it working with GetOneObjectAtOffset() so thanks for the help. I'd rather use GetObjectsAt but somehow I can't use it, it's like Greenfoot doesn't even know that that command exists. Do you have to add commands to your world or am I just dumb?
danpost danpost

2021/2/27

#
danpost wrote...
The World class has a getObjectsAt(int, int, java.lang.Class) method.
The 2nd word here says it all. Use: getWorld().getObjectsAt( ... )
You need to login to post a reply.