0

So in my menu for my game I want to be able to print out the high scores from a .txt file line by line, but with my current code it just adds all the scores to one line could someone please help?, I am using Livewires and Pygame.

    def highscores(self):

        sf = open('highscore.txt', 'r')
        highscores = sf.readlines()
        sf.close()

        thescores = games.Text(value = highscores, size = 32, color = color.green,
                   top = 130, right = 320)

        games.screen.add(thescores)
Callum Houghton
  • 25
  • 2
  • 13

1 Answers1

2

highscores is a list, so you need to loop over it:

def highscores(self):

        sf = open('highscore.txt', 'r')
        highscores = sf.readlines()
        sf.close()
        top = 130

        for highscore in highscores:
            thescores = games.Text(value = highscore, size = 32, color = color.green,
            top = top+10, right = 320)
            games.screen.add(thescores)
aIKid
  • 26,968
  • 4
  • 39
  • 65
  • 1
    I was about to writing the same answer. Note that you should adjust the `top` value for each line, otherwise all text lines will be drawn above each other. – sloth Nov 15 '13 at 15:12
  • This still prints out the same as before, apart from now the printed out high scores have brackets around them which tells me there in a list. It's probably something wrong with the Livewires library – Callum Houghton Nov 15 '13 at 16:07
  • Also, `value = highscores` should be `value = highscore` – sloth Nov 15 '13 at 16:24
  • Thanks for that, sorry i just able to fix it now. – aIKid Nov 16 '13 at 01:34