Brayden 7 сар өмнө
parent
commit
c5695af4d1
1 өөрчлөгдсөн 13 нэмэгдсэн , 7 устгасан
  1. 13 7
      GUI.py

+ 13 - 7
GUI.py

@@ -124,13 +124,19 @@ def load_scores():
         with open("all_scores.txt", "r") as f:
             lines = f.readlines()
             for line in lines:
-                name, score = line.strip().split(",")
-                score = float(score)
-                names.append(name)
-                scores.append(score)
-                if score > highestScore:
-                    highestScore = score
-                    highScoreName = name
+                line = line.strip()
+                if line and "," in line:  # Check if line is not empty and contains a comma
+                    try:
+                        name, score = line.split(",")
+                        score = float(score)
+                        names.append(name)
+                        scores.append(score)
+                        if score > highestScore:
+                            highestScore = score
+                            highScoreName = name
+                    except (ValueError, IndexError):
+                        # Skip malformed lines
+                        continue
     except FileNotFoundError:
         # Create the file if it doesn't exist
         with open("all_scores.txt", "w") as f: