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

2018/5/14

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. Error

OfficerRiot OfficerRiot

2018/5/14

#
so I keep getting this error but every time the bullet gets removed it crashes and do this here's the code. import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) /** * Write a description of class WalkerBullet here. * * @author (your name) * @version (a version number or a date) */ public class WalkerBullet extends Mover { private int chance = 0; boolean touchingGround = false; int range = 900; /** * Act - do whatever the WalkerBullet wants to do. This method is called whenever * the 'Act' or 'Run' button gets pressed in the environment. */ public void act() { move(5.0); hit(); turn(); } public void turn() { if ( ! getObjectsInRange( range, RifleTrooper.class ).isEmpty() ) { Actor pj = getObjectsInRange( range, RifleTrooper.class ).get( 0 ); turnTowards( pj.getX(), pj.getY() ); } } public void hit() { Actor walkerbullet = getOneIntersectingObject(Platform.class); if (walkerbullet != null) { if(touchingGround == false) { touchingGround = true; setImage("Explosion1.png"); getWorld().removeObject(this); } else { touchingGround = false; } } } }
danpost danpost

2018/5/14

#
OfficerRiot wrote...
so I keep getting this error but every time the bullet gets removed it crashes and do this << Code Omitted >>
The turn method requires the actor be in the world as it use getObjectsInRange immediately. It will fail if the actor is removed by the hit method, which is called before turrn in the act method. Simple act method fix is to call turn first -- then call hit.
OfficerRiot OfficerRiot

2018/5/14

#
Ah thanks
OfficerRiot OfficerRiot

2018/5/14

#
danpost wrote...
OfficerRiot wrote...
so I keep getting this error but every time the bullet gets removed it crashes and do this << Code Omitted >>
The turn method requires the actor be in the world as it use getObjectsInRange immediately. It will fail if the actor is removed by the hit method, which is called before turrn in the act method. Simple act method fix is to call turn first -- then call hit.
Actually, it seems like its still doing it
You need to login to post a reply.