I want to check if there's still an existing actor before running another method


if (someActor.getWorld() != null)
if ( ! getWorld().getObjects(SomeActor.class).isEmpty())
if (someActor.getWorld() != null)
if ( ! getWorld().getObjects(SomeActor.class).isEmpty())
public void exist(){ if ( ! getWorld().getObjects(runner.class).isEmpty()){ getWall(); } }
public class runner extends Actor { int health = 5; public void exist(){ if ( ! getWorld().getObjects(runner.class).isEmpty()){ getWall(); } } public void act() { exist(); health(); kill(); if(getWall() == false) { move(5); } else { int turn = Greenfoot.getRandomNumber(3); if(turn == 0) { turn(90); } else if (turn == 1){ turn(-90); } else if (turn == 2){ turn(180); } else if (turn == 3){ turn(-180); } } private boolean getWall(){ { GreenfootImage myImage = getImage(); int distance = myImage.getWidth()/2; int xOffset = (int)Math.ceil(distanceToFront*Math.cos(Math.toRadians(getRotation()))); int yOffset = (int)Math.ceil(distanceToFront*Math.sin(Math.toRadians(getRotation()))); Actor wall = getOneObjectAtOffset(xOffset, yOffset, wall.class); return(wall != null); } } public void health(){ Actor shot = getOneIntersectingObject(bullet.class); if (bullet != null) { health = health - 1; } } public void kill(){ if (health == 0){ getWorld().removeObject(this); } } }
if (getWorld() == null) return;