Title: i am trying to make a pause function with space key but it seems i cant even get in the pause function
Tags: python-3.x,pygame2

Question: #Opening and globals
from pygame.locals import *
import pygame
import time
import random
pygame.init()
WIDTH, HEIGHT = 1000, 800
WIN = pygame.display.set_mode((WIDTH, HEIGHT))
pygame.display.set_caption("Crypt Games")
BG = pygame.image.load("e:\\Pictures\\space.jpg")
PLAYER_WIDTH = 40
PLAYER_HIGHT = 60
PLAYER_VEL = 10
STAR_WIDTH = 10
STAR_HEIGHT = 20
STAR_VEL = 3
paused = False
clock = pygame.time.Clock()
keys = pygame.key.get_pressed()
PAUSEFONT = pygame.font.SysFont("comicsans", 100, True)
FONT = pygame.font.SysFont("comicsans", 30)

#Pause Function
def pause():
global paused
paused = True
while paused == True:
   for event in pygame.event.get():
       if event.type == pygame.QUIT:
          pygame.quit()
          quit()
       elif event.type == pygame.KEYDOWN:
            if event.type == pygame.K_SPACE:
            paused = False

    pause_text = PAUSEFONT.render("PAUSED", 1, "black")
    WIN.blit(pause_text, (WIDTH/2 - pause_text.get_width() /
                            2, HEIGHT/2 - pause_text.get_height()/2))
    pygame.display.update()
    clock.tick(60)

#Player Function
def draw(player, elapsed_time, stars):
WIN.blit(BG, (0, 0))
time_text = FONT.render(f"Time: {round(elapsed_time)}s", 1, "white")
WIN.blit(time_text, (10, 10))
pygame.draw.rect(WIN, "yellow", player)
for star in stars:
pygame.draw.rect(WIN, "white", star)
pygame.display.update()

#Main Game Loop
def main():
global paused
if paused == False:
run = True
player = pygame.Rect(200, HEIGHT - PLAYER_HIGHT,
PLAYER_WIDTH, PLAYER_HIGHT)
start_time = time.time()
elapsed_time = 0

        star_add_increment = 2000
        star_count = 0
        stars = []
        hit = False
        while run:
            star_count += clock.tick(60)
            elapsed_time = time.time() - start_time
    
            if star_count > star_add_increment:
                for _ in range(3):
                    star_x = random.randint(0, WIDTH - STAR_WIDTH)
                    star = pygame.Rect(star_x, -STAR_HEIGHT,
                                       STAR_WIDTH, STAR_HEIGHT)
                    stars.append(star)
                star_add_increment = max(200, star_add_increment - 50)
                star_count = 0

#this is where the problem is
(!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!)
    for event in pygame.event.get():
          if event.type == pygame.QUIT:
              run = False
              break
          elif event.type == pygame.KEYDOWN:
              if event.type == pygame.K_SPACE:
                  pause()

#Movement
keys = pygame.key.get_pressed()
if keys[pygame.K_LEFT] and player.x - PLAYER_VEL >= 0 or keys[pygame.K_a] and player.x - PLAYER_VEL >= 0:
player.x -= PLAYER_VEL
if keys[pygame.K_RIGHT] and player.x - PLAYER_VEL + player.width <= WIDTH - 26 or keys[pygame.K_d] and player.x - PLAYER_VEL + player.width <= WIDTH - 26:
player.x += PLAYER_VEL
for star in stars[:]:
star.y += STAR_VEL
if star.y > HEIGHT:
stars.remove(star)
elif star.y + star.height >= player.y and star.colliderect(player):
stars.remove(star)
hit = True
break
if hit:
lost_text = FONT.render("Game Over", 1, "white")
WIN.blit(lost_text, (WIDTH/2 - lost_text.get_width() /
2, HEIGHT/2 - lost_text.get_height()/2))
pygame.display.update()
pygame.time.delay(2000)
main()
draw(player, elapsed_time, stars)
else:
pygame.display.update()
pygame.quit()

if __name__ == "__main__":
main()

it seems that it CAN recognize the KEYDOWN (because i tested it without the elif) BUT NOT the "elif event.type == pygame.KSPACE:" order

Answer: never mind found it!i did a mistake!! its not event.type == pygame.K_SPACE but
event.key == pygame.K_SPACE. ...foolish