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

2021/2/14

Problem with numberOfObjects

rodut rodut

2021/2/14

#
Hi. I'm just learning Greenfoot. I have a problem with this function. This is my code:
 int nrrockets = numberOfObjects(Rocket.class); 
 if(nrrockets==0) 
{lives=lives-1;addObject(rocket,75,300);};
rodut rodut

2021/2/14

#
It says it cannot be applied to given types.
danpost danpost

2021/2/14

#
The numberOfObjects method has NO parameters and always returns the total number of Actor class objects in the world. Use:
if (getObjects(Rocket.class).isEmpty())
or
int nrrockets = getObjects(Rocket.class).size();
rodut rodut

2021/2/14

#
Thanks man. It works.
You need to login to post a reply.