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

2018/5/10

code not working

seslu seslu

2018/5/10

#
there is an error with the ending bracket which i dunno what to do about. (new to greenfoot btw) public void eatKey () { Actor Main = getOneIntersectingObject(Key.class); if(Key != null) getWorld().removeObject(Key); }
danpost danpost

2018/5/10

#
The intersecting object, if found, is an Actor object -- and more specifically, a Key object (an object of type Key). Your condition in the if clause is whether Key is null. The compiler only knows Key to be a Class object. It is not defined more locally to be anything else. But you cannot remove a Class object from the world -- you can only remove an Actor object (or an instance of a subclass of Actor) from the world. Look over the given code and see if you can determine exactly what you want the condition to check for a null status on (and remove from the world). HINT: what name did you give to a possible intersecting Key object?
You need to login to post a reply.