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 trial
Ian Z
14,584 PointsHow do you set permanent variables that persist even once you close program? (for high score boards);
i want to do something like
if(yourScore>highScore){
highScore = yourScore;
}
but make it permenently alter the code, so when i go open up Game.java highScore will now be set to the yourScore.
this is in java
1 Answer
William Li
Courses Plus Student 26,868 PointsHi, Ian, when executing the Game.java, the program is running on the computer's memory, and RAM is not a persistent storage, any trace of the program is wiped clean everytime you exit it.
In order to make permanent change, your program will have to write the value to a database or file (using PrintWriter, FileOutputStream , or sth similar), so that it gets stored in the hard drive, which unlike RAM, it's a permanent storage unit.
Ian Z
14,584 PointsIan Z
14,584 Pointscool, so it will have some kind of text file in the folder just like an image?
William Li
Courses Plus Student 26,868 PointsWilliam Li
Courses Plus Student 26,868 PointsYes, if you've played any kind of computer games, you'd know that most games have the feature of letting you save your game progress, and then later load it so that you may continue where you left off; well, that's because they created a save file somewhere on your hard drive, later it'll be able to load it to the game.