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

4 days ago

Check something is disappear in world

MianBao_Bread MianBao_Bread

4 days ago

#
I want make a game like pacman, now I want to end the game when all score disappear. This is my Code
if (getObjectsInRange(555, Score.class) == null) {
            Greenfoot.stop();
        }
It's not work, I want to know how to solve it. I am sorry that my English is not good.
danpost danpost

4 days ago

#
MianBao_Bread wrote...
I want make a game like pacman, now I want to end the game when all score disappear. This is my Code << Code Omitted >> It's not work, I want to know how to solve it. I am sorry that my English is not good.
The condition in line 1 will always be false. A List object is always returned by getObjectsInRange. You need to check the size of the list returned; or rather, check if it is an empty list
if (getObjectsInRange(555, Score.class).size() == 0) {

// or
if (getObjectsInRange(555, Score.class).isEmpty()) {

// or possibly
if (getWorld().getObjects(Score.class).isEmpty()) {
MianBao_Bread MianBao_Bread

3 days ago

#
danpost wrote...
MianBao_Bread wrote...
I want make a game like pacman, now I want to end the game when all score disappear. This is my Code << Code Omitted >> It's not work, I want to know how to solve it. I am sorry that my English is not good.
The condition in line 1 will always be false. A List object is always returned by getObjectsInRange. You need to check the size of the list returned; or rather, check if it is an empty list
if (getObjectsInRange(555, Score.class).size() == 0) {

// or
if (getObjectsInRange(555, Score.class).isEmpty()) {

// or possibly
if (getWorld().getObjects(Score.class).isEmpty()) {
Thanks! it can work.
You need to login to post a reply.