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 ?
for ((class) a : getObjectsInRange(radius, class)) { // code to execute }
if (!getObjectsInRange(10, Enemy.class).isEmpty())
{ Enemy enemy = getObjectsInRange(10, Enemy.class).get(0); // do stuff with 'enemy' }
Enemy enemy = (Enemy) getObjectsInRange(10, Enemy.class).get(0);
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); // ... }
for (Enemy a : (List<Enemy>) getObjectsInRange(10, Enemy.class)) { // code to execute }