I’m trying to get started with Pygame by creating a basic window, but I’m encountering a problem where my code starts to gray out in my editor, and I’m not sure what it means. I haven’t fully created the window yet, but I wanted to take the first few steps to get it running. Here’s the code I’m working with:
`import pygame
from pygame.locals import *
while True:
for event in pygame.event.get():
print(event)
running = True
while running:
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
pygame.quit()`
And, this is what it looks like when it is greyed out:
(https://i.sstatic.net/Um0sKxSE.png)
The problem arises when I type the line if event.type == pygame.QUIT:. After this line, my code starts to gray out, and it seems like my editor is indicating an issue, but I can’t figure out what it means or how to fix it. I use this coding extension called “Pylance” and this is what it had said: “Code is Unreachable” and I don’t know what that means.
Details:
- I’m using VS Code.
- The grayed-out section starts right after the line if event.type == pygame.QUIT:.
- I suspect it might have something to do with how I’ve written the conditional statement or maybe how I’ve structured the loop.
I tried to place that chunk of code before the “while True” section but still it wouldn’t work. I was just coding casually and I was expecting nothing to be greyed out.
Could someone help me understand what’s going wrong and how to fix this? I’m new to Pygame, so any additional tips would also be appreciated. Thank you!