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

2012/6/15

i need help as soon as possible

Benedict Benedict

2012/6/15

#
hi everyone, i got a problem (again) the following method in my scenario isn“t working:
public void getHurt()
    {
        setImage("death.PNG");
        Greenfoot.delay(4);
        getWorld().removeObject(this); 
    }
        
    public void die()
    {
        Actor a = getOneIntersectingObject(Ninjastar.class);
        if(a != null)
        {
            getHurt();
            getWorld().removeObject(a); 
        }
    }
thanking you in anticipation(for the hundred and first time ;) )
Benedict Benedict

2012/6/15

#
forgot to say what is not working :) if the Ninjastar "touches" the terrorist he s not disappearing
erdelf erdelf

2012/6/15

#
I dont really see why it shouldn't work, did you call the die method in act? If so, what happens, I mean happens anything?
Benedict Benedict

2012/6/15

#
yea, but every time the star tocuhes the actor there is a greenfoot error that says this : java.lang.NullPointerException at Terrorist.die(Terrorist.java:66) at Terrorist.act(Terrorist.java:23) at greenfoot.core.Simulation.actActor(Simulation.java:565) at greenfoot.core.Simulation.runOneLoop(Simulation.java:523) at greenfoot.core.Simulation.runContent(Simulation.java:213) at greenfoot.core.Simulation.run(Simulation.java:203) java.lang.NullPointerException at Terrorist.die(Terrorist.java:66) at Terrorist.act(Terrorist.java:23) at greenfoot.core.Simulation.actActor(Simulation.java:565) at greenfoot.core.Simulation.runOneLoop(Simulation.java:523) at greenfoot.core.Simulation.runContent(Simulation.java:213) at greenfoot.core.Simulation.run(Simulation.java:203) java.lang.NullPointerException at Terrorist.die(Terrorist.java:66) at Terrorist.act(Terrorist.java:23) at greenfoot.core.Simulation.actActor(Simulation.java:565) at greenfoot.core.Simulation.runOneLoop(Simulation.java:523) at greenfoot.core.Simulation.runContent(Simulation.java:213) at greenfoot.core.Simulation.run(Simulation.java:203)
TimbooXD TimbooXD

2012/6/15

#
remove line 14. getWorld().removeObject(a); and then compile that should work
Benedict Benedict

2012/6/15

#
thx, it worked :)
erdelf erdelf

2012/6/15

#
damn. didn't saw this
TimbooXD TimbooXD

2012/6/15

#
erdelf can you help me
erdelf erdelf

2012/6/15

#
whats your problem?
TimbooXD TimbooXD

2012/6/15

#
http://www.greenfoot.org/topics/1730
TimbooXD TimbooXD

2012/6/15

#
Benedict Benedict

2012/6/15

#
lol, im freaking out, another error: and i have no idea why: 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:663) at greenfoot.Actor.getOneObjectAtOffset(Actor.java:867) at Terrorist.canSee(Terrorist.java:72) at Terrorist.attack(Terrorist.java:78) at Terrorist.act(Terrorist.java:24) at greenfoot.core.Simulation.actActor(Simulation.java:565) at greenfoot.core.Simulation.runOneLoop(Simulation.java:523) at greenfoot.core.Simulation.runContent(Simulation.java:213) at greenfoot.core.Simulation.run(Simulation.java:203) i still have no idea what this will mean :(
erdelf erdelf

2012/6/15

#
code of the following methods from the Terrorist class: act() attack() canSee()
danpost danpost

2012/6/16

#
You are probably calling a method from the 'act' method, before the call to 'attack', where you are removing 'this' from the world'. Immediately after that method call, in the act method, that removes 'this' from the world, add the following line:
if (getWorld() == null) return;
Benedict Benedict

2012/6/16

#
it doesnt work and matter anymore, my teacher has the project already, but anyway, thank you all for your help :)
You need to login to post a reply.