-3
 keepGoing = True
 while keepGoing:
     score+=1
     myfont = pygame.font.SysFont("monospace", 15)
     label = myfont.render(str(score), 1, (255,255,0))
     screen.blit(label, (100, 100))

This is my code but when I run the program it increases score properly - but when outputting it to the screen it doesn't take previous digit off, so when it prints 1 on the screen and then a 2 the 1 doesn't erase the 2 shows write on top of it. Because of this after a while I just get a yellow block on the screen.

stuartd
  • 70,509
  • 14
  • 132
  • 163

3 Answers3

1

You're getting the error

NameError: name 'score' is not defined

because you're trying to update a variable that hasn't yet been defined. Even though the += contains an equal sign, you still need to define score before using +=

keepGoing = True
score = 0

while keepGoing:
    score += 1
aidnani8
  • 2,057
  • 1
  • 13
  • 15
0

you should define score out while, like

keepGoing = True
score = 0 

then it works.

0

I don't know python, but based on the symptoms my guess would be that you have to clear the screen before you write something new. This question might be the way to do that.

How to get rid of pygame surfaces?

Community
  • 1
  • 1
JasonMArcher
  • 14,195
  • 22
  • 56
  • 52