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

2013/11/3

Cannot find Symbol - Method size()

Balathasar Balathasar

2013/11/3

#
I am having a problem with this code: List<Enemy> Player1 = getObjectsInRange( 2000,Player1.class); if(Enemy.size()!=0){ pointAtObject(Enemy.get(0)); move(6.0); } I have it in the act(). It is complaining and saying: cannot find symbol - method size()
bourne bourne

2013/11/3

#
You named your List Player1, not Enemy
Balathasar Balathasar

2013/11/3

#
Thanks! I fixed and now am getting a new error. List<Player1> Enemy = getObjectsInRange( 2000,Player1.class); if(Enemy.size()!=0){ pointAtObject(Player1.get(0)); move(6.0); } It is telling me that it cannot find symbol - method get(int)
GreenHouse GreenHouse

2013/11/3

#
1
2
3
4
List<Player1> Enemy = getObjectsInRange(2000,Player1.class);
if(Enemy.size()!=0){
     pointAtObject(Enemy.get(0)); move(6.0);
 }
You named your List Enemy, not Player1
Balathasar Balathasar

2013/11/3

#
No matter what It continues to say that it cannot find get(int)
GreenHouse GreenHouse

2013/11/3

#
i changed Player1 to Enemy in line 3, did you notice that?
Balathasar Balathasar

2013/11/3

#
List<Player1> Enemy = getObjectsInRange(2000,Player1.class); if(Enemy.size()!=0){ pointAtObject(Enemy.get(0)); move(6.0); } Now it is saying: cannot find symbol - method pointAtObject(Player1`)
Balathasar Balathasar

2013/11/3

#
Also, Sorry I realized it once I posted it.
GreenHouse GreenHouse

2013/11/3

#
cannot find symbol - method pointAtObject(Player1) can you imagine what that means? :D i think java cannot find the method pointAtObject Have you created this method in your class?
Balathasar Balathasar

2013/11/3

#
I got this off a source. This is all it came with and is what I currently have in my Enemy class. What should I do? //this is at the top of the page where it should be. import java.util.List; //this is in the act() List<Player1> Enemy = getObjectsInRange(2000,Player1.class); if(Enemy.size()!=0){ pointAtObject(Enemy.get(0)); move(6.0); } //this is down below in the main code, not called in the act() public int pointTo(int x, int y) { int dX = x - getX();//get distance between mouse's X and player's X int dY = y - getY();//get distance between mouse's Y and player's Y double rotation = Math.atan2(dY, dX); rotation = Math.toDegrees(rotation); return (int)rotation; } Thanks :D
bourne bourne

2013/11/3

#
If Enemy is an Actor, using its turnTowards(int x, int y) method I think should do the same as your pointTo method. If in fact you are using the pointTo method's return value for setting the Actor's rotation
GreenHouse GreenHouse

2013/11/3

#
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
//this is at the top of the page where it should be.
import java.util.List;
 
public void act() {
 
    // here you get a list named 'Enemy' from type 'Player1'
    List<Player1> Enemy = getObjectsInRange(2000,Player1.class);
    // if list isn't empty
    if(Enemy.size()!=0){ 
        // call function pointAtObject with the first element
        // from list (the element is from type 'Player1')
        // but where is the function?!
        pointAtObject(Enemy.get(0));
        move(6.0); 
    }
}
 
// the method may look like this
// it will accept a parameter from type 'Player1'
void pointAtObject(Player1 player) {
 
    // do something with 'player'
 
 
 
}
You need to login to post a reply.