My pygame timer isn't stopping after it reaches the time limit

24 Views Asked by At

so I'm trying to make a game, but I've come into a problem.

I'm trying to make it so that when Enter is pressed, the program will start printing "text" for 1 second. When I run the code, it gets the input and starts printing, but it won't stop.

I really can't figure out why it isn't working so any help is appreciated.

My code:

#Assigning variables

attacking = False
stop_atk = pygame.USEREVENT + 1


#Functions that will be used in game loop

def player_atk():
    if event.type == pygame.KEYDOWN:
        if event.key == pygame.K_RETURN:
            attacking = True


def player_atk_do():
    if attacking:
        print("attacking")
        pygame.time.set_timer(stop_atk, 1000, 1)

        if pygame.event.get(stop_atk):
            print("stop_atk")
            attacking = False#Assigning variables
0

There are 0 best solutions below