Hello everybody! I've been trying for days but I can't manage to do it.
I want to remove an object from a world (when the object is clicked) and I want this object to be added to another world at the same time.
1.When I was searching how to do it from other discussions, I found that way to remove an object ((WorldName) getWorld()).removeObject(this);
and it worked only temporarily( when I went to another Word and then return to the previous one,the object was there again).
2.Although that problem existed, I thought that this command can be used to add an object too to another world ((OtherWorld)getWorld()).addObject(this,300,200);, but that gave me that error:
java.lang.NullPointerException
at key.act(key.java:33)
at greenfoot.core.Simulation.actActor(Simulation.java:594)
at greenfoot.core.Simulation.runOneLoop(Simulation.java:552)
at greenfoot.core.Simulation.runContent(Simulation.java:215)
at greenfoot.core.Simulation.run(Simulation.java:205)
Actor Class
I hope somebody can help me,I'm really stuck.Thanks in advance
public void act()
{
if (Greenfoot.mouseClicked(this)) {
((Fireplace) getWorld()).removeObject(this);
((Boy)getWorld()).addObject(this,300,200);
}}



