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

2016/11/7

types

Nosson1459 Nosson1459

2016/11/7

#
Box box  = getOneObjectAtOffset(-getImage().getWidth()/2+10, getImage().getHeight()/2 , Box.class);
return box != null&&box.isThere==true;
This code worked and then in middle of nowhere it said incompatible types actor cannot be converted to Box. Why not and why did it work before, when I didn't change anything, and I can't change the "Box box" to "Actor box" because then I cant access "isThere" .
danpost danpost

2016/11/7

#
Nosson1459 wrote...
Box box  = getOneObjectAtOffset(-getImage().getWidth()/2+10, getImage().getHeight()/2 , Box.class);
return box != null&&box.isThere==true;
This code worked and then in middle of nowhere it said incompatible types actor cannot be converted to Box. Why not and why did it work before, when I didn't change anything, and I can't change the "Box box" to "Actor box" because then I cant access "isThere" .
You just need to let the compiler know that the returned object of 'getOneObjectAtOffset' is indeed a Box object. The method is designed to return an Actor object. It cannot know beforehand what type you are going to specify. Insert '(Box)' before the method call.
You need to login to post a reply.