Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialAnshuman Tripathy
868 PointsStoring High Score dynamically and displaying it everytime program is compiled?
I'm having trouble with implementing this feature.
Someone had mentioned to store the HighScore variable statically in the Game class and to update it using a static function everytime a new high score is made.
But how do you do this?
I thought of having a finalScore variable too which stores the final score of the user just before the game ends (either win or loss). Then comparing the high score with the final score in the static function and updating the value of the HighScore variable.
BUT...We would need to initialize the values of finalScore and HighScore while defining them in Game.java
and everytime the program compiles won't those variable just take those initial values?
How do you make sure that High score from the previous program compilation persists?
1 Answer
Leo Tank
Full Stack JavaScript Techdegree Student 36,270 PointsProbably you should use a database or file to store highscores. https://docs.oracle.com/javase/tutorial/essential/io/file.html Cheers