Reputation:
I was programming a pygame project, I'll show you...
import pygame
pygame.init()
WHITE = (255, 255, 255)
pad_width = 1024
pad_height = 512
def runGame():
global gamepad, clock
crashed = False
while not crashed:
for event in pygame.event.get():
if event.type == pygame.QUIT:
crashed = True
gamepad.fill(WHITE)
pygame.display.update()
clock.tick(60)
pygame.quit()
def initGame():
global gamepad, clock
pygame.init()
gamepad = pygame.display.set_mode((pad_width, pad_height))
pygame.display.set_caption('Pyflying')
clock = pygame.time.Clock()
runGame()
initGame()
This is the code, now the error....
Traceback (most recent call last):
File "C:/Users/dongjune/Desktop/PyCharm/scratch.py", line 36, in <module>
initGame()
File "C:/Users/dongjune/Desktop/PyCharm/scratch.py", line 33, in initGame
runGame()
File "C:/Users/dongjune/Desktop/PyCharm/scratch.py", line 14, in runGame
for event in pygame.event.get():
pygame.error: video system not initialized
I don't know how to program this.... If you know the error, please answer!!! And, I'm a newbie to pygame.... ㅠ.ㅠ If you know how to use pygame please tell me! Thank you....
Upvotes: 0
Views: 384
Reputation: 194
Your indentation is wrong, fix this:
def runGame():
global gamepad, clock
crashed = False
while not crashed:
for event in pygame.event.get():
if event.type == pygame.QUIT:
crashed = True
gamepad.fill(WHITE)
pygame.display.update()
clock.tick(60)
# pygame.quit() Remove this line, it shouldn't be in a loop or just break after it's executed
Upvotes: 1