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

2017/12/16

Get Objects that aren't actors

NoaSakurajin NoaSakurajin

2017/12/16

#
I want to get all Objects that I created but the getObjects method just gives me the actors. Does anyone know a solution?
Super_Hippo Super_Hippo

2017/12/16

#
Only actors can be in the world, no other objects. So what you are trying to get?
NoaSakurajin NoaSakurajin

2017/12/16

#
I'm trying to get the Terminal
Super_Hippo Super_Hippo

2017/12/16

#
The terminal window? I doubt that you can use anything from the terminal window in your code. You also didn't "create" the terminal window.
NoaSakurajin NoaSakurajin

2017/12/16

#
Well I also have some classes that aren't subclasses of the actor. It would be nice to get those
Super_Hippo Super_Hippo

2017/12/16

#
The getObjects method returns objects which are in the world when it is called. An object of a class which isn't an actor can't be added to the world. To get an object of a non-actor class, you can't use this method. You can use static methods from this class or you have to save a reference to the object.
NoaSakurajin NoaSakurajin

2017/12/16

#
If it's like this then Greenfoot should fix the doc which says: public <A> java.util.List<A> getObjects(java.lang.Class<A> cls) Get all the objects in the world, or all the objects of a particular class. If a class is specified as a parameter, only objects of that class (or its subclasses) will be returned.
Super_Hippo Super_Hippo

2017/12/16

#
Well, you could add another 'in the world' at the end of the first sentence if it isn't clear to you. It really wouldn't make much sense if the world keeps a reference to all objects which are created (but not added to world) and doesn't ever remove the reference.
You need to login to post a reply.