0

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
notOli
  • 1
  • 2
  • 1
    You have to use a global variable, a class attribute or return the value somehow. In your code `attacking` is a local variable and wont be changed globally. – Jerry Aug 15 '22 at 19:42
  • 1
    @Jerry I didn't even think about that, thank you so much! – notOli Aug 15 '22 at 22:29

0 Answers0