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

2014/9/14

Reset

DarkSoulDemon DarkSoulDemon

2014/9/14

#
When i reset the game keeps the same score as when i died how can i make it so the score goes back down to zero
davmac davmac

2014/9/14

#
Is your score stored in a static variable? A static variable won't automatically reset. You could probably just set it to 0 in your world's constructor.
DarkSoulDemon DarkSoulDemon

2014/9/14

#
yes it is a static variable how would i set it to 0 in my world constructor
Super_Hippo Super_Hippo

2014/9/14

#
1
2
//replace 'score' with the name of the variable that stores the score
score = 0;
Just place it in the constructor of the class in which the variable is in.
DarkSoulDemon DarkSoulDemon

2014/9/14

#
where would i put that
Super_Hippo Super_Hippo

2014/9/14

#
In the constructor of the class. In one of your classes you will have something like
1
private static int score;
You put it in the constructor of this class. The constructor is a special method that every class automatically has. As default, it is empty. To overwrite it, you need to create it.
1
2
3
4
public Classname()
{
    score = 0;
}
Change 'Classname' to the name of the class. If you don't understand it, look at your world code. When you create a subclass of 'World', it will automatically create a constructor in it with 'super(600,400,1);' or something like that in it. (It's like a subclass of 'Actor' automatically comes with a empty 'act' method.) So create a constructor (if not there yet) in the class where you have the static variable and insert it there.
DarkSoulDemon DarkSoulDemon

2014/9/16

#
Thank you
You need to login to post a reply.