Very short and simple. I am trying to create a highscore txt document for one of the games I'm making apart of a project. I want it to be able to keep the highest score ever reached in a text document so I can display it on the screen.
The file already exists, but whenever I load up the game, I get a "invalid literal for int() with base 10:" error. After looking, I realised this was because the file would delete anything inside of it when the program is started. Why is this? How can I fix it?
My code:
hisc = open("snakeScore.txt","w+")
highscore = hisc.read()
highscore_in_no = int(highscore)
if score>highscore_in_no:
hisc.replace(str(score))
highscore_in_no = score