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

2011/12/21

Game trouble

1
2
3
4
5
jdemshki jdemshki

2011/12/22

#
i tried using this Actor bomb; bomb = getOneObjectAtOffset(0, 0, Bomb.class) ; if (bomb != null) { World world; world = getWorld(); world.removeObject(this); return; } in the bomb class and this happened. i still don't know how to read error messages 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:656) at greenfoot.Actor.getOneObjectAtOffset(Actor.java:860) at Bomb.disappear(Bomb.java:54) at Bomb.act(Bomb.java:33) at greenfoot.core.Simulation.actActor(Simulation.java:507) at greenfoot.core.Simulation.runOneLoop(Simulation.java:470) at greenfoot.core.Simulation.runContent(Simulation.java:204) at greenfoot.core.Simulation.run(Simulation.java:194) 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:656) at greenfoot.Actor.getOneObjectAtOffset(Actor.java:860) at Bomb.disappear(Bomb.java:54) at Bomb.act(Bomb.java:33) at greenfoot.core.Simulation.actActor(Simulation.java:507) at greenfoot.core.Simulation.runOneLoop(Simulation.java:470) at greenfoot.core.Simulation.runContent(Simulation.java:204) at greenfoot.core.Simulation.run(Simulation.java:194) 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:656) at greenfoot.Actor.getOneObjectAtOffset(Actor.java:860) at Bomb.disappear(Bomb.java:54)
danpost danpost

2011/12/22

#
The problem is that you are calling a method to remove the bomb (disappear) after the bomb was already removed. The other thing I see: you do not need to call 'getOneObjectAtOffset' to get a reference for 'this'. Post your act and disappear methods and I will look it over for you.
jdemshki jdemshki

2011/12/22

#
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) /** * Write a description of class Bomb here. * * @author (your name) * @version (a version number or a date) */ public class Bomb extends Mover /** * Act - do whatever the Bomb wants to do. This method is called whenever * the 'Act' or 'Run' button gets pressed in the environment. */ /** * Act - do whatever the castle wants to do. This method is called whenever * the 'Act' or 'Run' button gets pressed in the environment. */ /** * Act - do whatever the Blocker wants to do. This method is called whenever * the 'Act' or 'Run' button gets pressed in the environment. */ { public Bomb() { //image size GreenfootImage img = getImage(); int width = 40; int height = 40; img.scale (width, height);} public void act() { move(10.0) ; disappear() ; } public void disappear() {Actor castle; castle = getOneObjectAtOffset(0, 0, Castle.class) ; if (castle != null) { World world; world = getWorld(); world.removeObject(castle); world.removeObject(this); return; } if (this.atWorldEdge()) { World world; world = getWorld(); world.removeObject(this); } Actor bomb; bomb = getOneObjectAtOffset(0, 0, Bomb.class) ; if (bomb != null) { World world; world = getWorld(); world.removeObject(this); return; } } } here's the whole thing.
danpost danpost

2011/12/22

#
Remove nine (9) lines starting at the line 'Actor bomb;' and try it then.
jdemshki jdemshki

2011/12/22

#
it stopped showing the message. that was my attempt to make it disappear when it hits the blocker. how should i be doing that? i tried to just adjust my previous codes to do it but it failed.
danpost danpost

2011/12/22

#
Within the code where you check for atWorldEdge, again as the last statement, you need to put a 'return;'. Then you can add those lines back in, but ??? is your blocker a bomb ??? (why were you checking for a bomb here)
jdemshki jdemshki

2011/12/22

#
no my blocker is a rectangular thing that stops the bombs from continuing. i have castles on one side and I'm firing the bombs at them. i want the blocker to stop the bombs to add some difficulty to my game.
danpost danpost

2011/12/22

#
Then add the nine lines back into your code, BUT change what you are looking for (since it is not a bomb).
jdemshki jdemshki

2011/12/22

#
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:656) at greenfoot.Actor.getOneObjectAtOffset(Actor.java:860) at Bomb.disappear(Bomb.java:54) at Bomb.act(Bomb.java:33) at greenfoot.core.Simulation.actActor(Simulation.java:507) at greenfoot.core.Simulation.runOneLoop(Simulation.java:470) at greenfoot.core.Simulation.runContent(Simulation.java:204) at greenfoot.core.Simulation.run(Simulation.java:194) 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:656) at greenfoot.Actor.getOneObjectAtOffset(Actor.java:860) at Bomb.disappear(Bomb.java:54) at Bomb.act(Bomb.java:33) at greenfoot.core.Simulation.actActor(Simulation.java:507) at greenfoot.core.Simulation.runOneLoop(Simulation.java:470) at greenfoot.core.Simulation.runContent(Simulation.java:204) at greenfoot.core.Simulation.run(Simulation.java:194) 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:656) at greenfoot.Actor.getOneObjectAtOffset(Actor.java:860) at Bomb.disappear(Bomb.java:54) at Bomb.act(Bomb.java:33) at greenfoot.core.Simulation.actActor(Simulation.java:507) at greenfoot.core.Simulation.runOneLoop(Simulation.java:470) at greenfoot.core.Simulation.runContent(Simulation.java:204) at greenfoot.core.Simulation.run(Simulation.java:194) 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:656) at greenfoot.Actor.getOneObjectAtOffset(Actor.java:860) at Bomb.disappear(Bomb.java:54) at Bomb.act(Bomb.java:33) at greenfoot.core.Simulation.actActor(Simulation.java:507) at greenfoot.core.Simulation.runOneLoop(Simulation.java:470) at greenfoot.core.Simulation.runContent(Simulation.java:204) at greenfoot.core.Simulation.run(Simulation.java:194) 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:656) at greenfoot.Actor.getOneObjectAtOffset(Actor.java:860) at Bomb.disappear(Bomb.java:54) at Bomb.act(Bomb.java:33) at greenfoot.core.Simulation.actActor(Simulation.java:507) at greenfoot.core.Simulation.runOneLoop(Simulation.java:470) at greenfoot.core.Simulation.runContent(Simulation.java:204) at greenfoot.core.Simulation.run(Simulation.java:194) this happened
danpost danpost

2011/12/22

#
What did you add? Just show your disappear method this time.
jdemshki jdemshki

2011/12/22

#
this is the entire method; look after this for the part that is making it not work public void disappear() {Actor castle; castle = getOneObjectAtOffset(0, 0, Castle.class) ; if (castle != null) { World world; world = getWorld(); world.removeObject(castle); world.removeObject(this); return; } if (this.atWorldEdge()) { World world; world = getWorld(); world.removeObject(this); } Actor blocker; blocker = getOneObjectAtOffset(0, 0, Blocker.class) ; if (blocker != null) { World world; world = getWorld(); world.removeObject(this); return; } Here: Actor blocker; blocker = getOneObjectAtOffset(0, 0, Blocker.class) ; if (blocker != null) { World world; world = getWorld(); world.removeObject(this); return; }
danpost danpost

2011/12/22

#
You are still missing a 'return;' statement at the end of the atWorldEdge statement block.
jdemshki jdemshki

2011/12/23

#
that worked. what does return do?
jdemshki jdemshki

2011/12/23

#
i also want to make my main character thing only move up and down and i can't just rotate it like earlier because the shape won't work like that. how would i do that?
danpost danpost

2011/12/23

#
The return statement forces an exit of the current block of code or method. By adding the return statements in your code, you prevented later code from executing (which was causing the problem -- it was trying to process a 'getOneObjectAtOffset(int, int, class)' when there was no object to get an offset from, because it was previously removed. As far as rotate and your shape, you can still use rotate, but use it in combination with mirrorVertically() (if that does not do the trick, add mirrorHorizontally() also).
There are more replies on the next page.
1
2
3
4
5