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

2015/12/2

help what is wrong with this

itwasntme123 itwasntme123

2015/12/2

#
Actor food = getOneObjectAtOffset(0, 0, clss);
Super_Hippo Super_Hippo

2015/12/2

#
Where is this used? Is it in a method like this?
public void eat(Class clss)
{
    //...
}
If not, you could change 'clss' to the food class (or however it is called in your scenario):
Actor food = getOneObjectAtOffset(0, 0, Food.class);
itwasntme123 itwasntme123

2015/12/2

#
  public boolean isFood(Class clss)
    {
        Actor food = getOneObjectAtOffset(0, 0, clss);
        return food != null;

    }
Super_Hippo Super_Hippo

2015/12/2

#
The method is named 'isFood'. But the method gets another object of the passed class at the same position as this object and if there is one, it returns 'true' (and 'false' if not). If you want to check if an object is an instance of the Food class (which would make sense since the method was called 'isFood'), you could use 'instanceof'.
You need to login to post a reply.