-2

I keep getting a indentation error when adding a blit call to almost the end of this code, or anything else. I've been looking for the problem for over an hour but I can't find it. Could somebody take a look at it, please?

while True:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            pygame.quit()
            sys.exit()
      
        if event.type == pygame.KEYDOWN:
            if event.key == pygame.K_UP:
                speler_speed -= 6
            if event.key == pygame.K_DOWN:
                speler_speed += 6
        if event.type == pygame.KEYUP:
            if event.key == pygame.K_UP:
                speler_speed += 6
            if event.key == pygame.K_DOWN:
                speler_speed -= 6
    
    bal_animatie()
    player_animation()
    computer_ai()
    screen.fill(bg_color)
    pygame.draw.rect(screen, wit, player)
    pygame.draw.rect(screen, wit, computer)
    pygame.draw.ellipse(screen, wit, ball)
    pygame.draw.aaline(screen, wit, (screen_width /2, 0),(screen_width / 2, screen_height))
    speler_text = font.render(f'{speler_score}',False,wit)
    screen.blit(speler_text,(screen_width / 2 + 25, screen_height / 2 -15))
    computer_text = font.render(f'{computer_score}',False,wit)
    screen.blit(computer_text,(screen_width / 2 - 40, screen_height / 2 - 15))
The_spider
  • 1,202
  • 1
  • 8
  • 18
prolo06
  • 11
  • 1

1 Answers1

0

In a similar case, I was having a super difficult time finding out where the indentation was wrong in one of my code. If you are by chance using a bad editor (which doesn't support python), it wouldn't take care of indentations.
For python, a tab space and 4 spaces are not considered the same check each line to see if there is a combination of tabs and spaces used.
And make sure either all are spaces or all are tabs. 'd suggest you re indent all lines with tabs, and that should fix your issue.

vjspranav
  • 275
  • 1
  • 3
  • 11