Hello community, I am stuck.
I'm trying to make a RTS game (like "starcraft" or "age of empires") and iv decided to use the same method to get units that this scenario (http://www.greenfoot.org/scenarios/349) used (get all objects in range then remove all objects on the same faction from the list) honestly its pretty difficult reading through that code (there was alot >_<) and from what i could make out he initialized a list in his world class that contains units(which belong to a faction) and used that list to remove units belonging to the same faction when scanning for units in range.
so i made some lists in my world
public List<Unit> side0 = getObjects(Unit.class);
and in my units class im trying to use something like this to get enemies in range
public Units getNearestEnemy()
List<Units> list = getObjectsInRange(attackRange, Units.class);
list.removeAll(((Field)getWorld()).side0);//remove all units from same side from the list
so in order to do this i have to fill my list in my world up with units form the correct factions up first right?
so i tried to do this by putting
in my Unit class
and ofcourse when the unit die i will remove them from the list.
but i get an error and its because of ((Field)w).side0.add(this); and i dont understand why :|
i get a java.lang.NullPointerException i dont understand D: wtf makes no sense
public void addedToWorld(World w)
{
if(side == 0)
{
((Field)w).side0.add(this);
}
else if(side == 1)
{
((Field)w).side1.add(this);
}
else
{
((Field)w).side2.add(this);
}
}


