Jump to content

  • Log In with Google      Sign In   
  • Create Account


#Actualnickme

Posted 20 March 2013 - 01:30 PM

hi

 

i had written a program where i want to add xbox 360 controller support.

 

my program crashed when it said 'object Event has no attribute "key"'.  

 

 

            
        for event in pygame.event.get(): # event handling loop
            if event.type == QUIT:
                terminate()
            elif event.type == KEYDOWN or event.type == JOYAXISMOTION:                                     # by removing event.type == JOYAXISMOTION 
                                                                                                                                                        # the program run fine (ran without run time error).
                if (axis_x < 0.0 or event.key == K_LEFT or event.key == K_a) and direction != RIGHT:  # **** program crashed here. ****
                    direction = LEFT
                    print ' going L'
                elif (axis_x > 0. or event.key == K_RIGHT or event.key == K_d) and direction != LEFT:
                    print ' going R'
                    direction = RIGHT
 
it seen that pygame did not recognize event.key when i had the second event checked (the or statement).  is there a way to check both the KEYDOWN and JOYAXISMOTION in a single if statement?  because otherwise, i would have to handle it in a separate block of codes. and it could be logically unsound. imagine if some user uses both keyboard and joystick at the same time!
 
thanks

#2nickme

Posted 18 March 2013 - 04:09 PM

hi

 

i had written a program where i want to add xbox 360 controller support.

 

my program crashed when it said 'object Event has no attribute "key"'.  

 

 

            
        for event in pygame.event.get(): # event handling loop
            if event.type == QUIT:
                terminate()
            elif event.type == KEYDOWN or event.type == JOYAXISMOTION:                                     # by removing event.type == JOYAXISMOTION 
                                                                                                                                                        # the program run fine.
                if (axis_x < 0.0 or event.key == K_LEFT or event.key == K_a) and direction != RIGHT:  # **** program crashed here. ****
                    direction = LEFT
                    print ' going L'
                elif (axis_x > 0. or event.key == K_RIGHT or event.key == K_d) and direction != LEFT:
                    print ' going R'
                    direction = RIGHT
 
it seen that pygame did not recognize event.key when i had the second event checked (the or statement).  is there a way to check both the KEYDOWN and JOYAXISMOTION in a single if statement?  because otherwise, i would have to handle it in a separate block of codes. and it could be logically unsound. imagine if some user uses both keyboard and joystick at the same time!
 
thanks

#1nickme

Posted 18 March 2013 - 03:15 PM

hi

 

i had written a program where i want to add xbox 360 controller support.

 

my program crashed when it said 'object Event has no attribute "key"'.  

 

 

            
        for event in pygame.event.get(): # event handling loop
            if event.type == QUIT:
                terminate()
            elif event.type == KEYDOWN or event.type == JOYAXISMOTION:                                     # by removing event.type == JOYAXISMOTION 
                                                                                                                                                        # the program run fine.
                if (axis_x < 0.0 or event.key == K_LEFT or event.key == K_a) and direction != RIGHT:  # **** program crashed here. ****
                    direction = LEFT
                    print ' going L'
                elif (axis_x > 0. or event.key == K_RIGHT or event.key == K_d) and direction != LEFT:
                    print ' going R'
                    direction = RIGHT
 
it seen that pygame did not recognize event.key when i had the second event checked.  is there a way to check both the KEYDOWN and JOYAXISMOTION in a single if statement?  because otherwise, i would have to handle it in a separate block of codes.
 
thanks
 
 

PARTNERS