We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hi guys, it looks like my BufferedReader doesnt read my txt file.
Basically i want to save my Highscore in a Snake game.
But if I start a new game my Highscore stays always at 10! even if i reset it or in my txt file stands other staff like 39.
Here my Code
updateHighscore(){ if(highscore < s.score){ highscore = s.score; //Create a new file in the sketch directory output = createWriter(highscoreDatei); output.println(highscore); output.close(); // Writes the remaining data to the file & Finishes the file } } importHighscore(){ // Open the file from the createWriter() reader = createReader(highscoreDatei); if(reader==null){ highscore = 0; return; } String zeile; try{ zeile = reader.>readLine(); }catch (IOException e){ e.printStackTrace(); zeile = null; } if(zeile != null){ highscore = int(zeile); //println(highscore) } try{ reader.close(); }catch (IOException e){ e.printStackTrace(); } }
importHighscore() is in the setup function and updateHighscore() is in my gameOver() function. Btw the updateHighscore() function works well, the txt gets always updated.
Hope anyone can help me. Thanks
Answers
Your code excerpt is badly indented. Processing's IDE (PDE) got auto-indentation using CTRL+T.
For something so simple like saving the score, why not loadStrings() & saveStrings() instead?
Ok, thanks for the tipps :D