Welcome to the CSC Q&A, on our server named in honor of Ada Lovelace. Write great code! Get help and give help!
It is our choices... that show what we truly are, far more than our abilities.

Categories

+5 votes

For the final project, some of us might be creating games and would want to save the highest score of the game. In order to do this, you might want to create a text file and write the new highest score to file every time there is a new highest score. The reason why you will want to immediately write the new highest score to the file is for it to be saved in case the game stops working for some reason. Then at the beginning of the function you are using, you should read from the same text file to display the highest score so far. Someone might have a better way of doing this if so, let us know.

asked in CSC201 Spring 2021 by (1 point)

2 Answers

+2 votes

I cannot think of a way other than the text file where a variable will be saved when the code ends. I believe every other way we have learned will make the variable retention end when the code ends. I feel the biggest challenge would be getting rid of the old highest score whenever it changes. Text file seems the way for this though.

answered by (1 point)
+2 votes

I think that a file is the best way to do this. I don't think there is any better way to do this.

answered by (1 point)
...