danpost wrote...
RandomGuy wrote...
same error I posted a day agopublic void act() { movement(); if (isAtEdge()) { collidesWithZombie(); getWorld().removeObject(this); } }
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); } }
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)
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() { } }
public void act() { move(6); if (isAtEdge() || collidesWithZombie()) { getWorld().removeObject(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() {
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() {
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() {