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

2014/12/9

Keep getting incompatibale types, Sys.out.pr. was just for testing

berdie berdie

2014/12/9

#
public void act() 
 {
       if(!getWorld().getObjects(MainBoat.class).isEmpty()) {         
           Actor boat = getWorld().getObjects(MainBoat.class);
           if (boat.getX()>=102 && boat.getX <= 136 && boat.getY()==729){              
               System.out.println("Ja");
          }
   
      }
    }   
danpost danpost

2014/12/9

#
You are declaring a variable of type Actor on line 4; but, trying to assign a List object to it (returned from 'getObjects').
Berdie1 Berdie1

2014/12/9

#
for some Reason my account got blocked, when i try to show a image in the comment. On topic: If I try to declare it as a list i can't use the getX method
danpost danpost

2014/12/9

#
You do not want to declare it as a List. You want to declare it as an Actor; but you need to get the actor from the list before you can set your field to it:
Actor boat = (Actor)getWorld().getObjects(MainBoat.class).get(0);
Berdie1 Berdie1

2014/12/9

#
Could u give me any tips on how i have to do that?
danpost danpost

2014/12/9

#
Replace line 4 in your post above with the line 1 just gave.
Berdie1 Berdie1

2014/12/9

#
danpost wrote...
Replace line 4 in your post above with the line 1 just gave.
Ty very much!
berdie berdie

2014/12/9

#
Hey, I fixed that problem saw that problem when googling, but when i declare as List i won't be able to use getX() or getY()
You need to login to post a reply.