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

2023/3/21

How to remove Bullet from world

1
2
3
4
5
6
RandomGuy RandomGuy

2023/3/28

#
danpost wrote...
RandomGuy wrote...
same error I posted a day ago
What error did you get with my code? Please copy/paste error trace output here for examination (using my code).
java.lang.IllegalStateException: Actor has been removed from the world. at greenfoot.Actor.failIfNotInWorld(Actor.java:722) at greenfoot.Actor.isAtEdge(Actor.java:266) at Bullet.act(Bullet.java:24) at greenfoot.core.Simulation.actActor(Simulation.java:567) at greenfoot.core.Simulation.runOneLoop(Simulation.java:530) at greenfoot.core.Simulation.runContent(Simulation.java:193) at greenfoot.core.Simulation.run(Simulation.java:183) Caused by: greenfoot.ActorRemovedFromWorld at greenfoot.World.removeObject(World.java:466) at Mythic2.removeObject(Mythic2.java:46) at Bullet.movement(Bullet.java:49) at Bullet.act(Bullet.java:23) ... 4 more java.lang.IllegalStateException: Actor has been removed from the world. at greenfoot.Actor.failIfNotInWorld(Actor.java:722) at greenfoot.Actor.isAtEdge(Actor.java:266) at Bullet.act(Bullet.java:24) at greenfoot.core.Simulation.actActor(Simulation.java:567) at greenfoot.core.Simulation.runOneLoop(Simulation.java:530) at greenfoot.core.Simulation.runContent(Simulation.java:193) at greenfoot.core.Simulation.run(Simulation.java:183) Caused by: greenfoot.ActorRemovedFromWorld at greenfoot.World.removeObject(World.java:466) at Mythic2.removeObject(Mythic2.java:46) at Bullet.movement(Bullet.java:49) at Bullet.act(Bullet.java:23) ... 4 more
RandomGuy RandomGuy

2023/3/29

#
danpost wrote...
RandomGuy wrote...
same error I posted a day ago
What error did you get with my code? Please copy/paste error trace output here for examination (using my code).
Sorry for complicating this so here is my act code bel
public void act()
    {
        movement();
        if (isAtEdge())
        {
 
            collidesWithZombie(); getWorld().removeObject(this);
        }
    }
ow
RandomGuy RandomGuy

2023/3/29

#
danpost wrote...
RandomGuy wrote...
same error I posted a day ago
What error did you get with my code? Please copy/paste error trace output here for examination (using my code).
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
 
/**
 * Write a description of class Bullet here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class Bullet extends Actor
{
 
    /**
     * Act - do whatever the Bullet wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    public Bullet()
    {
 
    }
 
    public void act()
    {
        movement();
        if (isAtEdge())
        {
 
            collidesWithZombie(); getWorld().removeObject(this);
        }
    }
 
danpost danpost

2023/3/29

#
RandomGuy wrote...
danpost wrote...
RandomGuy wrote...
same error I posted a day ago
What error did you get with my code? Please copy/paste error trace output here for examination (using my code).
Sorry for complicating this so here is my act code bel << Code Omitted >> ow
Try copy/pasting my code for the Bullet class into your Bullet class editor, replacing everything you currently have in it; then see what happens. If an error occurs in the Bullet class, then copy/paste the error trace for examination.
RandomGuy RandomGuy

2023/3/29

#
danpost wrote...
RandomGuy wrote...
danpost wrote...
RandomGuy wrote...
same error I posted a day ago
What error did you get with my code? Please copy/paste error trace output here for examination (using my code).
Sorry for complicating this so here is my act code bel << Code Omitted >> ow
Try copy/pasting my code for the Bullet class into your Bullet class editor, replacing everything you currently have in it; then see what happens. If an error occurs in the Bullet class, then copy/paste the error trace for examination.
java.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:681)
	at greenfoot.Actor.isAtEdge(Actor.java:254)
	at Bullet.act(Bullet.java:24)
	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)
java.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:681)
	at greenfoot.Actor.isAtEdge(Actor.java:254)
	at Bullet.act(Bullet.java:24)
	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)
RandomGuy RandomGuy

2023/3/29

#
The error above is what I keep getting on terminal
RandomGuy RandomGuy

2023/3/29

#
danpost wrote...
RandomGuy wrote...
danpost wrote...
RandomGuy wrote...
same error I posted a day ago
What error did you get with my code? Please copy/paste error trace output here for examination (using my code).
Sorry for complicating this so here is my act code bel << Code Omitted >> ow
Try copy/pasting my code for the Bullet class into your Bullet class editor, replacing everything you currently have in it; then see what happens. If an error occurs in the Bullet class, then copy/paste the error trace for examination.
So when I put the boolean code into my act method as per usual, this error pops up: java.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:681) at greenfoot.Actor.isAtEdge(Actor.java:254) at Bullet.act(Bullet.java:24) 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) java.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:681) at greenfoot.Actor.isAtEdge(Actor.java:254) at Bullet.act(Bullet.java:24) 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) java.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:681) at greenfoot.Actor.isAtEdge(Actor.java:254) at Bullet.act(Bullet.java:24) 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) java.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:681) at greenfoot.Actor.isAtEdge(Actor.java:254) at Bullet.act(Bullet.java:24) 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)
RandomGuy RandomGuy

2023/3/29

#
danpost wrote...
RandomGuy wrote...
danpost wrote...
RandomGuy wrote...
same error I posted a day ago
What error did you get with my code? Please copy/paste error trace output here for examination (using my code).
Sorry for complicating this so here is my act code bel << Code Omitted >> ow
Try copy/pasting my code for the Bullet class into your Bullet class editor, replacing everything you currently have in it; then see what happens. If an error occurs in the Bullet class, then copy/paste the error trace for examination.
Also, I will point out that my zombies which respawn get hit by the same bullet
danpost danpost

2023/3/29

#
RandomGuy wrote...
Also, I will point out that my zombies which respawn get hit by the same bullet
That error trace must be on your code, not mine. Your isAtEdge call is at line 24 of your act method. My act method is on lines 5 through 8. In fact, my entire class code for Bullet is only 17 lines long. It it impossible for it to error on line 24.
RandomGuy RandomGuy

2023/3/29

#
danpost wrote...
RandomGuy wrote...
Also, I will point out that my zombies which respawn get hit by the same bullet
That error trace must be on your code, not mine. Your isAtEdge call is at line 24 of your act method. My act method is on lines 5 through 8. In fact, my entire class code for Bullet is only 17 lines long. It it impossible for it to error on line 24.
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
 
/**
 * Write a description of class Bullet here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class Bullet extends Actor
{
 
    /**
     * Act - do whatever the Bullet wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    public Bullet()
    {
 
    }
 
    public void act()
    {
        movement();
        if (isAtEdge())
        {
 
            collidesWithZombie(); getWorld().removeObject(this);
        }
        collidesWithZombie();
    }
 
    private boolean collidesWithZombie() {
        if ( ! isTouching(Zombies.class)) return false;
        { Greenfoot.playSound("Gunshot.mp3");
            removeTouching(Zombies.class);
            ((Counter)getWorld().getObjects(Counter.class).get(0)).add(1);
            return true;
        }
    }
 
    private void movement()
    {
        move(6);
 
        if (isAtEdge())
        {
            World world = getWorld();
            if(world != null)
            {
                world.removeObject(this);
                return;
 
            } 
        }
         
 
    }
 
    private void repeat()
    {
 
    }
}
RandomGuy RandomGuy

2023/3/29

#
I don't see anything here(correct me if I am wrong)? Please send me an edited version of my code if possible. It might work?
danpost danpost

2023/3/29

#
RandomGuy wrote...
I don't see anything here(correct me if I am wrong)? Please send me an edited version of my code if possible. It might work?
Remove lines 41 through 54 and change your act method to this:
public void act() {
    move(6);
    if (isAtEdge() || collidesWithZombie()) {
        getWorld().removeObject(this);
    }
}
RandomGuy RandomGuy

2023/3/29

#
danpost wrote...
RandomGuy wrote...
I don't see anything here(correct me if I am wrong)? Please send me an edited version of my code if possible. It might work?
Remove lines 41 through 54 and change your act method to this:
public void act() {
    move(6);
    if (isAtEdge() || collidesWithZombie()) {
        getWorld().removeObject(this);

Thanks the error is fixed but my bullet isn't removed?
[code]import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
 * Write a description of class Bullet here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class Bullet extends Actor
{

    /**
     * Act - do whatever the Bullet wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    public Bullet()
    {

    }

    public void act() {
        move(6);
        if (isAtEdge() || collidesWithZombie()) {
            getWorld().removeObject(this);
        }
    }

    private boolean collidesWithZombie() {
        
} }
Anything wrong?Bullet doesn't want to remove?
RandomGuy RandomGuy

2023/3/29

#
RandomGuy wrote...
danpost wrote...
RandomGuy wrote...
I don't see anything here(correct me if I am wrong)? Please send me an edited version of my code if possible. It might work?
Remove lines 41 through 54 and change your act method to this:
public void act() {
    move(6);
    if (isAtEdge() || collidesWithZombie()) {
        getWorld().removeObject(this);
Sooy i accidentally wrote my comment in my code:)

Thanks the error is fixed but my bullet isn't removed?
[code]import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
 * Write a description of class Bullet here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class Bullet extends Actor
{

    /**
     * Act - do whatever the Bullet wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    public Bullet()
    {

    }

    public void act() {
        move(6);
        if (isAtEdge() || collidesWithZombie()) {
            getWorld().removeObject(this);
        }
    }

    private boolean collidesWithZombie() {
        
} }
Anything wrong?Bullet doesn't want to remove?
RandomGuy RandomGuy

2023/3/29

#
RandomGuy wrote...
RandomGuy wrote...
danpost wrote...
RandomGuy wrote...
I don't see anything here(correct me if I am wrong)? Please send me an edited version of my code if possible. It might work?
Remove lines 41 through 54 and change your act method to this:
public void act() {
    move(6);
    if (isAtEdge() || collidesWithZombie()) {
        getWorld().removeObject(this);

Sooy i accidentally wrote my comment in my code:)

Thanks the error is fixed but my bullet isn't removed?
[code]import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
 * Write a description of class Bullet here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class Bullet extends Actor
{

    /**
     * Act - do whatever the Bullet wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    public Bullet()
    {

    }

    public void act() {
        move(6);
        if (isAtEdge() || collidesWithZombie()) {
            getWorld().removeObject(this);
        }
    }

    private boolean collidesWithZombie() {
        
} }
Anything wrong?Bullet doesn't want to remove?
Sorry I wrote my comments in the code.My bullet doesn't disappear when it touches the zombie anyway?
There are more replies on the next page.
1
2
3
4
5
6