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

2015/10/18

Boss

Zinks2 Zinks2

2015/10/18

#
Hey- I am having a problem setting up a damage system for my boss. I have tried to put him under a boss class, but then I get an illeagal state exception actor not in world every time I fire. I've tried putting the damage code inside my boss using if (this !=null) but then it just dies instantly. I am trying to avoid having another world for my bosses, so any suggestions as to how I can get around this will be much apreciated. Thank you!
Psychpsyo Psychpsyo

2015/10/18

#
How does your damage system looks like? I have made a Boss myself. He has a variable called HP (healthpoints) and always looses one, when I damge him. If it is smaller than 1 he dies.
Zinks2 Zinks2

2015/10/18

#
Same system; It's refarancing the method i'm having problems with. I always get an illeagal state exprssion
Psychpsyo Psychpsyo

2015/10/18

#
Can you post your code here?
danpost danpost

2015/10/18

#
First, an error, or rather your code, cannot be fixed without seeing the code you were using. Second 'this != null' will always be true; knowing what you were trying to ask might help here. In other words, you are giving very little information to go on. Supplying your problem code will go a long way; but, may in itself not be enough. Oftentimes, the code to more than one class may be required (you suggest a Boss class and a class under it; then a class that fires which may be one of those classes; what is fired would probably be another class, as well).
Zinks2 Zinks2

2015/10/18

#
This is my boss class; import greenfoot.*; /** * Write a description of class Discor here. * * @author (your name) * @version (a version number or a date) */ public class Discor extends Actor { int shotTimer=0; int stageTimer=0; int bHealth=5; int upTimer=50; /** * Act - do whatever the Turret wants to do. This method is called whenever * the 'Act' or 'Run' button gets pressed in the environment. */ public void act() { int Y=getY(); int X=getX(); stageTimer=stageTimer+1; upTimer=upTimer+1; if (stageTimer > 0) { if (stageTimer < 500) { if (shotTimer == 0) { EvilBullet b; b = new EvilBullet(); getWorld().addObject(b, X, Y); shotTimer = 30; } if (shotTimer > 0) { shotTimer = shotTimer - 1; } if (upTimer > 0) { if (upTimer < 50) { setLocation(getX(), getY() - 3); } } if (upTimer > 50) { if (upTimer < 100) { setLocation(getX(), getY() + 3); } } if (upTimer > 100) { upTimer=0; } } } if (stageTimer > 500) { if (stageTimer < 550) { turn (5); setLocation(getX(), getY() - 3); if (shotTimer == 0) { EvilBullet b; b = new EvilBullet(); getWorld().addObject(b, X, Y); shotTimer = 5; } if (shotTimer > 0) { shotTimer = shotTimer - 1; } } } if (stageTimer > 550) { if (stageTimer < 600) { turn (5); setLocation(getX(), getY() + 3); if (shotTimer == 0) { EvilBullet b; b = new EvilBullet(); getWorld().addObject(b, X, Y); shotTimer = 5; } if (shotTimer > 0) { shotTimer = shotTimer - 1; } } } if (stageTimer > 600) { if (stageTimer < 1100) { if (shotTimer == 0) { EvilBullet b; b = new EvilBullet(); getWorld().addObject(b, X, Y); shotTimer = 30; } if (shotTimer > 0) { shotTimer = shotTimer - 1; } if (upTimer > 0) { if (upTimer < 50) { setLocation(getX(), getY() - 3); } } if (upTimer > 50) { if (upTimer < 100) { setLocation(getX(), getY() + 3); } } if (upTimer > 100) { upTimer=0; } } } if (stageTimer > 1100) { if (stageTimer < 1150) { turn (5); setLocation(getX(), getY() + 3); if (shotTimer == 0) { EvilBullet b; b = new EvilBullet(); getWorld().addObject(b, X, Y); shotTimer = 5; } if (shotTimer > 0) { shotTimer = shotTimer - 1; } } } if (stageTimer > 1150) { if (stageTimer < 1200) { turn (5); setLocation(getX(), getY() - 3); if (shotTimer == 0) { EvilBullet b; b = new EvilBullet(); getWorld().addObject(b, X, Y); shotTimer = 5; } if (shotTimer > 0) { shotTimer = shotTimer - 1; } } } if (stageTimer > 1200) { stageTimer=0; } } public void bDamage() { bHealth=bHealth-1; if (bHealth < 1){ World world; world = getWorld(); SpaceWorld spaceWorld = (SpaceWorld) getWorld(); spaceWorld.increaseScore(1); world.removeObject(this); } } }
danpost danpost

2015/10/18

#
Zinks2 wrote...
Same system; It's refarancing the method i'm having problems with. I always get an illeagal state exprssion
Please post (copy/paste) the entire error message along with the trace. Also use code tags when posting code (read the page linked to the 'Posting code? read this!' link below the 'Post a reply' box.
Zinks2 Zinks2

2015/10/18

#
It's just an actor not in world error. It's because it wants to use a method when that thing that contains the method isn't there.
danpost danpost

2015/10/18

#
Zinks2 wrote...
It's just an actor not in world error. It's because it wants to use a method when that thing that contains the method isn't there.
I am aware of what it means when you get that particular error message. No extra information was given with your last posting. It would help to post the actual error message given.
Zinks2 Zinks2

2015/10/19

#
Sorry I this took time; I was AFK for a while. The error message reads; 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.getOneObjectAtOffset(Actor.java:885) at Bullet.act(Bullet.java:50) 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) And the line of code it has an issue with is in my bullet class: Discor d; d = (Discor) getOneObjectAtOffset (0, 0, Discor.class); if(d != null) { d.bDamage(); } Do you know how I can ask it to check if my boss is presant before it runs the code?
danpost danpost

2015/10/19

#
The following line of your error message:
1
at Bullet.act(Bullet.java:50)
tells me that the error occurred at line 50 of the Bullet class. in the 'act' method. This line:
1
at greenfoot.Actor.getOneObjectAtOffset(Actor.java:885)
tells me that you are trying to use 'getOneObjctAtOffset', probably on the bullet either before it (the bullet) is placed into the world or after it was removed from the world. The Bullet class is the code that needs provided to determine how to fix it.
Zinks2 Zinks2

2015/10/19

#
Bullet Code;import greenfoot.*; import java.util.List; /** * Write a description of class Bullet here. * * @author (your name) * @version (a version number or a date) */ public class Bullet extends Actor { boolean aimBot; /** * Act - do whatever the Bullet wants to do. This method is called whenever * the 'Act' or 'Run' button gets pressed in the environment. */ public void act() { List<Actor> rocks = getWorld().getObjects(Enemy.class); if (!aimBot || rocks.isEmpty()) { move (10); } else { Actor target = rocks.get(0); turnTowards(target.getX(), target.getY()); move(10); } if (getX () > getWorld().getWidth() -5) { World world; world = getWorld(); world.removeObject(this); return; } Enemy enemy; enemy = (Enemy) getOneIntersectingObject (Enemy.class); if(enemy != null) { enemy.die(); getWorld().removeObject(this); //spaceWorld.increaseScore(1); } Discor d; d = (Discor) getOneObjectAtOffset (0, 0, Discor.class); if(d != null) { d.bDamage(); } } public Bullet(boolean _aimBot) { aimBot=_aimBot; } }
danpost danpost

2015/10/19

#
danpost wrote...
use code tags when posting code (read the page linked to the 'Posting code? read this!' link below the 'Post a reply' box.
I am not about to count the lines to see which line is line number 50. The 'if' block before the last 'if' block in the act method of the Bullet class has code to remove the bullet from the world. If this occurs then you cannot follow with 'getOneObjectsAtOffset' because calling that method requires the actor be in the world. Add a 'return;' statement at the end of the 'if' code block the removes the bullet from the world when intersecting an Enemy object.
Zinks2 Zinks2

2015/10/19

#
Ok; i will try it! Thx!
You need to login to post a reply.