Skip to content Skip to sidebar Skip to footer

Attribute Error : Member Not Defined Python

Hi there I'm trying to detect if the 'w' key is pressed and I keep getting an error and can't see where I've went wrong. Grateful for advice. while 1: for event in pygame.e

Solution 1:

You have to check event.type == pygame.KEYDOWN or event.type == pygame.KEYUP before you use event.key because not all events have event.key defined.

whileTrue: 
    foreventin pygame.event.get():
        ifevent.type == pygame.QUIT: 
            sys.exit()
        elif event.type == pygame.KEYDOWN: 
            ifevent.key == pygame.K_w:    #line 82
                player.walkNorthAnimation()

see PyGame documentation: Event

QUIT             none
ACTIVEEVENT      gain, state
KEYDOWN          unicode, key, mod
KEYUP            key, mod
MOUSEMOTION      pos, rel, buttons
MOUSEBUTTONUP    pos, button
MOUSEBUTTONDOWN  pos, button
JOYAXISMOTION    joy, axis, value
JOYBALLMOTION    joy, ball, rel
JOYHATMOTION     joy, hat, value
JOYBUTTONUP      joy, button
JOYBUTTONDOWN    joy, button
VIDEORESIZE      size, w, h
VIDEOEXPOSE      none
USEREVENT        code

Post a Comment for "Attribute Error : Member Not Defined Python"