I'm trying to add a pause function to my Pygame, but there's an error constantly coming up --> UnboundLocalError: local variable 'pause' referenced before assignment
I don't know how to solve this, and I've re-arranged the code a couple of times. Any help would be appreciated. Code is down below...
#PAUSING
if pause:
screen.fill((0, 0, 0))
pause_text = font2.render("PAUSE",True,(255,255,255))
screen.blit(pause_text, (468 - (pause_text.get_width() // 2), 368 - (pause_text.get_height() // 2)))
pause = False
pause_time = 0 #Time spent with the game paused
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_p:
if pause:
pause = False
pause_time += time.time() - pause_time_start
else:
pause = True
pause_time_start = time.time()
As I mentioned earlier, the output should be pausing the game. For this, I'd just like for someone to show me the proper way to arrange the code.