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

2015/4/30

trying to make a score based on time and unsure how

Hombow Hombow

2015/4/30

#
I have three bits of code that make up the counter This is in the background to allow access to the actor generating the points:
private Cover cover;
...
public Cover returnCover()
{
    return cover;
}
This is the code in the actor that generates and returns the points:
boolean go = true;
int points = 0
...
if(go == false)#this is when the game has started
{
    Background background = (Background) getWorld();
    Background.newLine();
    points++;
}
this is the code for the actor that is needed to make the background display the points as the other is removed to stop the points have been counted.
Cover cover2 = background.returnCover();
cover2.getPoints();
world.removeObjects(cover);
I know something is wrong with the code but I'm not sure what.
Super_Hippo Super_Hippo

2015/4/30

#
Change the first line to
private Cover cover = new Cover();
Then, when adding it to the world, you have something like this:
addObject(cover, 100, 100);
The second line of the third part of code gets the points, but doesn't use or save it.
cover2.getPoints();
Well, I don't see the method, but I guess it's a normal getter method.
danpost danpost

2015/5/1

#
The last line of code given, 'getWold().removeObject(cover);', uses 'cover'-- not 'cover2'. I cannot say if this is what you want or not; but, I did not see 'cover' defined or used elsewhere in the class. If you are trying to remove the Cover object that is returned by 'returnCover' in your Background class, then 'cover' needs to be changed to 'cover2' in that line.
Hombow Hombow

2015/5/6

#
cover is defined elsewhere in the class is defined elsewhere as they occupy the same space but I can't use the same cover to get the cover.points()
Hombow Hombow

2015/5/6

#
background is the world class just to clarify
danpost danpost

2015/5/6

#
Please post the entire Cover class code.
Hombow Hombow

2015/5/6

#
I have fixed it now thank you for the help
You need to login to post a reply.