wrap score reading in try/except in case unreadable characters are written

This commit is contained in:
ohsqueezy 2023-01-02 01:35:02 -05:00
parent 23023d594e
commit 5a57b50693
1 changed files with 8 additions and 5 deletions

View File

@ -434,11 +434,14 @@ class Scoreboard(GameChild):
def set_scores(self):
self.scores = []
with open(self.scores_path, "r") as fp:
for line in fp:
fields = line.split()
self.scores.append((float(fields[0]), int(fields[1]), fields[2]))
fp.close()
try:
with open(self.scores_path, "r") as fp:
for line in fp:
fields = line.split()
self.scores.append((float(fields[0]), int(fields[1]), fields[2]))
fp.close()
except:
print("Warning: error while reading scores file. Ignoring for now.")
self.scores = sorted(self.scores, key=itemgetter(0))
self.scores = sorted(self.scores, key=itemgetter(1), reverse=True)