title: Pygame - Unknown error in a multiplayer control function
body: <p>I am making a two player game in which two players can move simultaneously throughout. </p>
  
  <p>The while loop goes like this:</p>
  
  <pre><code>while stop==0:
  
  for event in pygame.event.get():
      if event.type == pygame.QUIT:
          stop = 1
  
          #For player 1
      #on pressing an arrow key
      # xv, yv = velocity at which the object moves
      elif event.type == pygame.KEYDOWN:
  
          if event.key == pygame.K_LEFT:
              xv = -1
          elif event.key == pygame.K_RIGHT:
              xv = 1
          elif event.key == pygame.K_UP:
              yv = -1
          elif event.key == pygame.K_DOWN:
              yv = 1
              #         on releasing an arrow key
      elif event.type == pygame.KEYUP:
  
          if event.key == pygame.K_LEFT or event.key == pygame.K_RIGHT:
              xv = 0
          elif event.key == pygame.K_UP or event.key == pygame.K_DOWN:
              yv = 0
  
      #For player 2
  
      elif event.type == pygame.KEYDOWN:
  
          if event.key == pygame.K_a:
              xv2 = -1
          elif event.key == pygame.K_d:
              xv2 = 1
          elif event.key == pygame.K_w:
              yv2 = -1
          elif event.key == pygame.K_s:
              yv2 = 1
                  #         on releasing an arrow key
      elif event.type == pygame.KEYUP:
  
          if event.key == pygame.K_a or event.key == pygame.K_d:
              xv2 = 0
          elif event.key == pygame.K_w or event.key == pygame.K_s:
              yv2 = 0
  </code></pre>
  
  <p>Using the above code, only player 1 was able to move while player 2 remained still.</p>
  
  <p>but after modifying the code like this it worked,</p>
  
  <pre><code>while stop==0:
  
  for event in pygame.event.get():
      if event.type == pygame.QUIT:
          stop = 1
  
          #For player 1
       #on pressing an arrow key
      # xv, yv = velocity at which the object moves
      elif event.type == pygame.KEYDOWN:
  
          if event.key == pygame.K_LEFT:
              xv = -1
          elif event.key == pygame.K_RIGHT:
              xv = 1
          elif event.key == pygame.K_UP:
              yv = -1
          elif event.key == pygame.K_DOWN:
              yv = 1
              #         on releasing an arrow key
      elif event.type == pygame.KEYUP:
  
          if event.key == pygame.K_LEFT or event.key == pygame.K_RIGHT:
              xv = 0
          elif event.key == pygame.K_UP or event.key == pygame.K_DOWN:
              yv = 0
  
      #For player 2
      if event.type == pygame.QUIT:
          stop = 1
      elif event.type == pygame.KEYDOWN:
  
          if event.key == pygame.K_a:
              xv2 = -1
          elif event.key == pygame.K_d:
              xv2 = 1
          elif event.key == pygame.K_w:
              yv2 = -1
          elif event.key == pygame.K_s:
              yv2 = 1
                  #         on releasing an arrow key
      elif event.type == pygame.KEYUP:
  
          if event.key == pygame.K_a or event.key == pygame.K_d:
              xv2 = 0
          elif event.key == pygame.K_w or event.key == pygame.K_s:
              yv2 = 0
  </code></pre>
  
  <p>The only change made was inserting</p>
  
  <pre><code>        if event.type == pygame.QUIT:
          stop = 1
  </code></pre>
  
  <p>before the elif statement of player 2. Can anyone help with this confusion?</p>