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

2011/7/23

getObjectsInRange

Advenging Advenging

2011/7/23

#
How can I delete a class with the method getObjectsInRange ? Just like in the wombat-scenario the leaf would delete. The first idea : public void mauerberuhrt2() { getObjectsInRange (80, seifenblase.class); if(seifenblase.class!= null) { getWorld().removeObject(seifenblase.class); } } Thx for your answers and sry for my bad english. Advenging
Herman Herman

2011/7/23

#
Hm, "No results found" is the result of a "getObjectsInRange" search using the Greenfoot search method. I guess we have to invoke a super here :-)
danpost danpost

2011/7/23

#
With 'getObjectsInRange(80, seifenblase.class);', you are creating a list, but you need a variable name to reference that list: i.e. 'List<seifenblase>objects = getObjectsInRange(80, seifenblase.class);'. Then if any are in range: 'if (objects.size > 0) { getWorld().removeObjects(objects); }' You will have to use 'import java.util.List;' or 'import java.util.*;' at the beginning of your class code to use 'List'. In the Wombat scenario, there was a variable of 'Leaf' class that referenced the deleted leaf. Also, notice the parameter for 'removeObjects(java.util.collection)' which requires a list; where in Wombat scenario, 'removeObject(Actor)' gets a single Actor object.
Advenging Advenging

2011/7/26

#
Thx thx thx for your answers. Danpost: I have added your code but when I want it compile. The throws come --cannot find symbol - variable size--. public void mauerberuehrt2() { List<seifenblase>objects = getObjectsInRange(30,seifenblase.class); /***inrange ueberprueft ob sich sb im radius 30 von m als ursprung bef.***/ if (objects.size > 0) { /**getWorld().removeObjects(objects);**/ ((meineWelt) getWorld()).gameover(); } /***wenn j dann gameover***/ } Where should I install the var size ??????? That is really bewildering. Advenging
colorfulteen colorfulteen

2011/7/26

#
Size is a variable and size() is the method you want.
Advenging Advenging

2011/7/26

#
A big thx colorful. Now it works. Have a nice day. Advenging
danpost danpost

2011/7/26

#
@Advenging, 'my bad', I knew it was a method, but forgot to apply the '()'
You need to login to post a reply.