title: While Loops with functions and states in python
body: <p>I have a school project I've been religiously trying to get working. I've tried indenting, De-denting, defining local and global variables, and even asking my teacher. To no avail. What i want to happen while in state 3, is when you click on a button, it changes the state within the function and once the loop finishes, the state changes and therefore so does the while loop.</p>
  
  <pre><code>def buttonCollide():
  mouse = pygame.mouse.get_pos()
  click = pygame.mouse.get_pressed()
  textSurf, textRect = text_objects("Level 1", smallText)
  textRect.center = (200,250)
  screen.blit(textSurf, textRect)
      if 170+100 &gt; mouse[0] &gt; 130 and 270+50 &gt; mouse[1] &gt; 170: ### BUTTON 1
          pygame.draw.circle(screen,selected_white,(200,250),70,0)
          textSurf, textRect = text_objects("Level 1", smallText)
          textRect.center = (200,250)
          screen.blit(textSurf, textRect)
          if 170+100 &gt; mouse[0] &gt; 130 and 270+50 &gt; mouse[1] &gt; 200 and event.type == pygame.MOUSEBUTTONDOWN:
          state = 4
  
  while state == 3:
      for event in pygame.event.get():
          if event.type == pygame.QUIT:
              pygame.quit()
              sys.exit()
              quit()
      screen.fill(dark_blue)
      drawMenu()
      buttonCollide()
      pygame.display.update()
  </code></pre>
  
  <p>It should switch to state 4 after this loop exits ButtonCollide(), but for some reason it constantly sets the state back to 3 after it exits the function.</p>