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

2013/1/7

actor not in world

KierTulp KierTulp

2013/1/7

#
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:
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); 
   
        }
    }    
}
thanks in advance :D
KierTulp KierTulp

2013/1/7

#
I just fixed the magnet one, it was because I had the getX() and getY() thingies in there.
You need to login to post a reply.