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

2016/6/19

Get amount of one object

Julian109998 Julian109998

2016/6/19

#
Hi everyone I'm still at my program for school and need a little help again.
int beamamount = 0;
    public void powermove(){
        if(health>0){
            beamamount = getWorld().getObjects(beam); //get the beam amount here but how ?
            if(beamamount >=1 ){
                if (powermover <= 0){
                    if (Greenfoot.isKeyDown("a")){
                        move (-250);
                        powermover = powermover +100;
                    }
                    if(Greenfoot.isKeyDown("d")){
                        move (250);
                        powermover = powermover +200;
                    }

                }
                else{
                    powermover = powermover - 1;
                }
            }
        }
    }
here you see my Code and my question is how can I get the amount of beams that is actually in my world as an int ?
danpost danpost

2016/6/19

#
The World class API documentation shows that the 'getObjects' method returns a 'java.util.List' object -- not an 'int' value. Go to the API documentation of the List class, here, and find a method that returns the required 'int' value.
You need to login to post a reply.