Update on the exam, WJEC sent a message to the invigilator to tell us not to do question 9 at all - question 9 is the Greenfoot question. This because somebody messed up the code for the counter
Help, I got everything to work but when the counter increases, it automatically decreases. My exams are in a few weeks and I'm hoping to get this to work because not even my teacher knows how to and I want to try and get full marks with Greenfoot. Please help.
Woozle 03 Productions Check you haven’t got another piece of code decrementing the counter somewhere. Compare the code carefully. Also make sure you are not adding the counter every time something happens otherwise the default value of zero will be implemented.
Yeah, what had happened was I didn't have an actor for my counter which was my mistake. Not sure if it's working now, but I'll let you know once I go to my class.
declare 'score' in the counter class (before any method) public int score = 0; then just add these lines to the main actor's class (at the bottom of the act method) Counter counter = (Counter) getWorld().getObjects(Counter.class).get(0); counter.score = counter.score + 1 if you need to take away score (e.g a secondary actor taking away score if it collides with the main actor) then simply put those lines into the secondary actor's class and change the + 1 to - 1
Mr A Heard -I tried the method in the video but there is one problem: in my main actor where I typed "Counter counter = Ocean.getCounter ();" there is an error on "getCounter" that says non static method getCounter() cannot be referenced from a static context.