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

2015/4/27

Problem with "getObjectsInRange"

1
2
danpost danpost

2015/4/27

#
Alright, insert the following method in the world class:
public void checkCharakters()
{
    System.out.println("***  Charakter1 objects ***\n");
    int n=0;
    for (Object obj : getObjects(Charakter1.class))
    {
        n++;
        Actor actor = (Actor) obj;
        System.out.println("("+n+")\n   x: "+actor.getX()+"\n   y: "+actor.getY()+"\n");
    }
}
Then compile, run, pause and right click on world to select this method. Report what is printed out to the terminal.
davmac davmac

2015/4/28

#
What version of Greenfoot are you running?
xWanna xWanna

2015/4/28

#
That shows the terminal
*** Charakter1 objects *** (1) x: 118 y: 120
My Greenfoot version is 2.4.0
danpost danpost

2015/4/28

#
Oh -- I see the problem now. It is at line 13 in your door class (your first code post in this discussion thread). 'getObjectsInRange' will never return a null value. You need to check to see if the List object that is returned is empty or not.
if ( !getObjectsInRange(40, Charakter1.class).isEmpty() && ... 
xWanna xWanna

2015/4/28

#
Oh -- I see the problem now. It is at line 13 in your door class (your first code post in this discussion thread). 'getObjectsInRange' will never return a null value. You need to check to see if the List object that is returned is empty or not. ? 1 if ( !getObjectsInRange(40, Charakter1.class).isEmpty() && ...
Oh, thanks man. It's working now. :D
You need to login to post a reply.
1
2