0

Why does it say NameError: name 'walk_count2' is not defined when it is defined? I also called the function in a while loop. I also called the function in a while loop.

def animations():

    global walk_count1
    global walk_count2
    screen.fill((45,45,45))
    idle[0] = pygame.transform.scale(idle[0], (20,60))
    walkRight[0] = pygame.transform.scale(walkRight[0], (30,60))
    if walk_count2 + 1 >= 2:
        walk_count2 = 0
    if walk_count1 + 1 >= 10:
        walk_count1 = 0

    if right:
        screen.blit(walkRight[walk_count2//3], (player_location))
        walk_count2 += 1


    if still:
        screen.blit(idle[walk_count1//3], (player_location))
        walk_count1 += 1

    pygame.display.update()
Rabbid76
  • 177,135
  • 25
  • 101
  • 146
habo
  • 1
  • You have to set `walk_count2` before you can read it. Somewhere in global namespace you must set `walk_count2 = 0` (e.g. right before `def animations():`) – Rabbid76 Sep 21 '21 at 19:02

0 Answers0