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

2016/4/1

Update 3.0.2 "broke" scenario

Psychpsyo Psychpsyo

2016/4/1

#
I just downloaded Greenfoot 3.0.2 today and wanted to edit one of my older scenarios, where at one point an actor accesses a method from another actor. It worked fine before the update but now it says the method doesn't exists. Here's the code of the two actors (the one accessing the method is called Building, the other is called Ground): Method in Building: public int getGround() { setLocation(getX(), getY() + 16); int givenType; if(isTouching(Ground.class) == true) { givenType = getOneIntersectingObject(Ground.class).getType(); //Here is the error } else { givenType = 0; } setLocation(getX(), getY() - 16); return givenType; } Method in Ground: public int getType() { return type; } And yes, all the variables used in the methods exist.
danpost danpost

2016/4/1

#
I believe that it is not known to look in the Ground class for the method because the object returned by 'getOneIntersectingObject' is know only as an Actor object -- not as a Ground object. A typecast is needed to let the system know to look in the Ground class for the method:
givenType = ((Ground)getOneIntersectingObject(Ground.class)).getType();
Super_Hippo Super_Hippo

2016/4/1

#
I wonder how it worked in an earlier version. Change the line to this:
givenType = ((Ground) getOneIntersectingObject(Ground.class)).getType();
Psychpsyo Psychpsyo

2016/4/1

#
Thanks for the fast answers. It works now. But I still wonder, why it worked before...
You need to login to post a reply.