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

2014/9/1

HELP ME SCORE COUNTER PROBLEM

1
2
danpost danpost

2014/9/3

#
Line 54 declares the field 'counters' to hold a Counters object and sets it to a newly created Counters object. This Counters object is what is returned by your 'getCounters' method. But, this is NOT the Counters object you added into your world. Line 299 declares a local 'counters' field to hold a Counters object and sets it to a newly created Counters object and line 300 adds this Counters object into the world. First, the local 'counters' field is not the same field as the world instance field named 'counters'; and, the Counters object is not the same as that held by the world instance Counters field. So, any changes in the value of the Counters object returned by 'getCounters', which is the Counters object that is not in the world, is not reflected by the Counters object that is in the world. By removing line 299, the reference to 'counters' on line 300 will then refer to the world instance Counters field object.
sharifahhilwa sharifahhilwa

2014/9/3

#
@danpost OMG IT WORKED!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! THANK YOU SO MUCH DAN!!! YOU HELPED ME ALOT THROUGHOUT ALL OF MY DISCUSSION!!! thank you so much!!
sharifahhilwa sharifahhilwa

2014/9/3

#
oh but wait terminal window pop out
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.getOneIntersectingObject(Actor.java:912)
	at Crosser.eat(Crosser.java:53)
	at Crosser.act(Crosser.java:44)
	at greenfoot.core.Simulation.actActor(Simulation.java:568)
	at greenfoot.core.Simulation.runOneLoop(Simulation.java:526)
	at greenfoot.core.Simulation.runContent(Simulation.java:215)
	at greenfoot.core.Simulation.run(Simulation.java:205)
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.getOneIntersectingObject(Actor.java:912)
	at Crosser.eat(Crosser.java:53)
	at Crosser.act(Crosser.java:44)
	at greenfoot.core.Simulation.actActor(Simulation.java:568)
	at greenfoot.core.Simulation.runOneLoop(Simulation.java:526)
	at greenfoot.core.Simulation.runContent(Simulation.java:215)
	at greenfoot.core.Simulation.run(Simulation.java:205)
davmac davmac

2014/9/3

#
Just like the exception message says, you are calling a method (getOneIntersectingObject) which relies on the actor being in the world, but the actor (Crosser) has been removed from the world. You need to avoid calling getOneIntersectingObject after the actor removes itself from the world.
You need to login to post a reply.
1
2