hello, I have coded a button which should turn on a magnet in the level. when the magnet is turned on it will create a beam which pulls up my actor.
I can drag the button into the level, but nothing happens when I press it, also, when i try to put in the magnet or the beam it will give me this error:
ava.lang.IllegalStateException: Actor not in world. An attempt was made to use the actor's location while it is not in the world. Either it has not yet been inserted, or it has been removed.
at greenfoot.Actor.failIfNotInWorld(Actor.java:663)
at greenfoot.Actor.getX(Actor.java:157)
at Magnet.<init>(Magnet.java:11)
this is my code:
thanks in advance :D
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) public class Knop extends Scroll { public boolean knopAan; public void act() { move(7); isXPressed(); } public boolean isUmanNear() { if(!getObjectsInRange(40, Uman.class).isEmpty()) { return true; } else { return false; } } public void isXPressed() { if(isUmanNear()) { if(Greenfoot.isKeyDown("x")) { knopAan = true; } } } }
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) public class Magnet extends Knop { public int X = getX(); public int Y = getY(); public void act() { move(7); } public void on() { if(knopAan = true) { GravityUp GravityUp = new GravityUp(); getWorld().addObject(GravityUp, 200,200+ 40); } } }