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

2017/3/18

help

bdbornilla bdbornilla

2017/3/18

#
what is wrong with my code? it keeps on showing a red underline on counter.add(10) public void addScore() { Actor candywrapper; candywrapper = getOneObjectAtOffset(0,0, CandyWrapper.class); if(candywrapper !=null) { World world; world = getWorld(); world.removeObject(candywrapper); counter.add(10); } }
Super_Hippo Super_Hippo

2017/3/18

#
How should it know what 'counter' is?
bdbornilla bdbornilla

2017/3/19

#
what do you mean?
Fifilein Fifilein

2017/3/19

#
You need/should to create a variable counter.Maybe something like that:
//a new method for your Worldclass
 public  Counter getCounter()
   {
      return counter; 
    }
//add that instead of  counter.addScore(10); 

    Worldclass wc = (Worldclass)world;
         Counter counter = wc.getCounter();
         counter.addScore(10); 
Can you show your errormessage?
Super_Hippo Super_Hippo

2017/3/19

#
bdbornilla wrote...
what do you mean?
I mean that you use 'counter' but nowhere in the code shown above you declare what 'counter' is. So you could write some random letters instead and will get the same result.
You need to login to post a reply.