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

2017/3/16

Greenfoot terminal window keeps opening

Avilianne Avilianne

2017/3/16

#
The terminal window keeps opening and it states that "Actor not in world. An attempt was made to use the actor's location while it in not on the world....." I'm trying to remove an object when another object touches it and that keeps popping up.
danpost danpost

2017/3/16

#
There should be an error trace along with that message. Post it here along with the class of the object being removed.
Avilianne Avilianne

2017/3/16

#
I may have done something to make it stop popping up but my object (pizza) wont disappear now. I'm really sorry about the topic change, I'm new to this and I just keep changing the code.
 public void act() 
    {
        setLocation(getX(), getY()-2);

        if (getY() == 0) 
        {
            getWorld().removeObject(this);
        }   
    }
 
    public void checkCollission()
    {
     if (isTouching(Bear.class))
        {   
            getWorld().removeObject(this);
        }
    }
}
 public void act() 
    {
        checkKeyPress();// Add your action code here.

        if(!isTouching(Pizza.class))
        {
            setLocation(getX(),getY()+2);
        }
    }

    private void checkKeyPress()
    {
        if (Greenfoot.isKeyDown("left")) 
        {
            setLocation(getX()-4, getY());
        }

        if (Greenfoot.isKeyDown("right")) 
        {
            setLocation(getX()+4, getY());
        }
        if (Greenfoot.isKeyDown("space") && !pressed)
        {
            setLocation ( getX(), getY()+vSpeed);
            vSpeed = vSpeed + acceleration;
            pressed = true;
        }
        if (!Greenfoot.isKeyDown("space") && pressed)
        {
            pressed = false;
        }

    }

    public void jump()
    {
        vSpeed = -16;
    }
    
    public void checkCollission()
    {
     if (isTouching(Bear.class))
        {   
           removeTouching(Pizza.class);
        }
    }
public MyWorld()
    {    
        // Create a new world with 600x400 cells with a cell size of 1x1 pixels.
        super(600, 400, 1); 
        Bear bear = new Bear();
        addObject(bear, 50, 73);    
        Pizza pizza = new Pizza();
        addObject(new Pizza(),Greenfoot.getRandomNumber(600), 350);
    }

    public void act()
    {
        if (Greenfoot.getRandomNumber(100) < 3)
        {
            addObject(new Pizza(),Greenfoot.getRandomNumber(600), 350);
        }
    }
}
danpost danpost

2017/3/16

#
It does not look like you went too far ahead with this issue. Remove ALL collision checking from both the Bear and Pizza classes and then try again. Only put collision checking between two objects in one of the two classes. Best might be to put the code in the Bear class since the Pizza already removes itself upon hitting the edge of the world -- and it would be the Bear object that causes the Pizza object to disappear upon collision between the two.
Avilianne Avilianne

2017/3/16

#
Thank you so much! It worked
Avilianne Avilianne

2017/3/16

#
uhm... it popped up again, and now it's longer...
danpost danpost

2017/3/16

#
Avilianne wrote...
uhm... it popped up again, and now it's longer...
Looks like you dropped an 'm' in the extension to a reference to an 'mp3' sound file (called 'NomNom').
You need to login to post a reply.