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

2015/12/9

Check if Enemies dead

A2O A2O

2015/12/9

#
So I have this wave of enemies arriving as you spawn. Now I want a new wave of enemies spawn right after the last one standing of the last wave dies.
if( getWorld().getObjects( Enemie.class ) == null)
            {
                phase = 1;
            }
I did it like this. It doesnt work, dont judge me. Halp? ^^
danpost danpost

2015/12/9

#
The List object returned by 'getObjects' will never be null -- it might be an empty list (in that it contains no objects), but it is still a List object. Use the 'isEmpty' method of the List class on the returned List object:
if (getWorld().getObjects(Enemie.class).isEmpty())
A2O A2O

2015/12/9

#
what exactly is null tho? sounds stoopid, but I may aswell ask it now
danpost danpost

2015/12/9

#
The keyword 'null' represents the absence of an object. You can declare a variable to hold a List object:
List enemies;
Since no value (no List object) is assigned to the 'enemies' variable, it retains a 'null' value. Often you will see something like this:
World world;
world = getWorld();
before the second line is executed, 'world' does not reference any World object. Even after it is executed, that may still be the case if the actor is not currently in any world. The java tutorials states that the value of a 'null' reference is "undetermined" (it does not point to any object, at the moment).
A2O A2O

2015/12/9

#
Makes sense, thanks.
You need to login to post a reply.