Going crazy trying to figure out why my counter (the one imported from within Greenfoot)
wont work:
I have the following in MyWorld:
Counter counter = new Counter();
I have the following in my Player (to get a point when it eats something)
Note, that the commented out code works. But why does it not work as it stands now?
1 2 3 4 | public Counter getCounter() { return counter; } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | public void act() { Actor eat = getOneObjectAtOffset( 0 , 0 , Food. class ); if (eat != null ) { getWorld().removeObject(eat); //World world; //world = getWorld(); //Counter counter = (Counter) (getWorld().getObjects(Counter.class).get(0)); //counter.add(1); MyWorld world; world = (MyWorld)getWorld(); Counter counter = world.getCounter(); counter.add( 1 ); } |