hello, i'm fairly new to Greenfoot and haven't used lists before. Could someone please tell me how to use the method 'getObjectsInRange(int radius, java.lang.Class cls)' and how to use the output - maybe some sort of actor array ?


1 2 3 4 | for (( class ) a : getObjectsInRange(radius, class )) { // code to execute } |
1 | if (!getObjectsInRange( 10 , Enemy. class ).isEmpty()) |
1 2 3 4 | { Enemy enemy = getObjectsInRange( 10 , Enemy. class ).get( 0 ); // do stuff with 'enemy' } |
1 | Enemy enemy = (Enemy) getObjectsInRange( 10 , Enemy. class ).get( 0 ); |
1 2 3 4 5 6 7 8 9 | import java.util.List; // at the top of the source file! ... List<Enemy> l = getObjectsInRange( 10 , Enemy. class ); if (! l.isEmpty()) { Enemy e = l.get( 0 ); // ... } |
1 2 3 | for (Enemy a : (List<Enemy>) getObjectsInRange( 10 , Enemy. class )) { // code to execute } |