BufferedReader doenst read

edited January 2016 in Questions about Code

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

Sign In or Register to comment.