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

2015/2/25

What does Get Objects do?

etbillder etbillder

2015/2/25

#
I'm trying to make a new world when all the objects of a class are removed. I'm wondering if using the getOjbects class would work. Any suggestions?
Max-Felix Max-Felix

2015/2/25

#
hmm getObjects(___.class) gives you a list of the objects of the class maybee you can check if that list is empty but i didnt tryed it yet :o
etbillder etbillder

2015/2/25

#
I'm (pretty sure I'm) doing that, but I'm not sure how to get the values from the list (number of objects, etc.).
danpost danpost

2015/2/26

#
etbillder wrote...
I'm wondering if using the getOjbects class would work.
First, 'getObjects' is not a class, but a method. It is a member of the World class provided by greenfoot. If you look at the greenfoot.World class API documentation and check out the 'getObjects' method, you will find that it returns a List object. From there, you can check out the java.util.List class API documentation to see what methods are available for List object and what they do.
etbillder etbillder

2015/2/26

#
How do I make the list a variable? I have this written so far:
1
2
3
4
5
6
7
8
9
public void isRemoved() {
        getObjects(Enemey.class);
        countObjects();
        if(list) {
            Greenfoot.playSound("upgrade.wav");
            Lvl2 lvl2 = new Lvl2();
            Greenfoot.setWorld(lvl2);
        }
    }
I just put something random in the if statement.
etbillder etbillder

2015/2/26

#
Never mind, I figured it out. :)
You need to login to post a reply.