KattyTheEnby
KattyTheEnby

Reputation: 97

Python keeps crashing with pygame function

I can't get python to work when I am using my Raycast function to display images, how do I fix this?

I tried moving some variables and played around with the function, but I can't seem to get it to work.

import pygame
pygame.init()

Screen = "Title"
DB = 0
Width = 800
Height = 600

Frame = pygame.display.set_mode((Width,Height))
pygame.display.set_caption("GAME")
FPS = pygame.time.Clock()

def Raycast(RayXPos, RayYPos):
    RaycastThis = pygame.image.load(TTR)
    Frame.blit(RaycastThis, (RayXPos, RayYPos))
    Loop = True
    while Loop == True:
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                exit()
    pygame.display.update()

    FPS.tick(60)

    while Screen == "Title" and DB == 0:
        TTR = 'TitleScreenSmall.png'
        Raycast(0, 0)

I expected the frame to display the image (the same size as the window) and it instead crashed, and I can't run the program

Upvotes: 0

Views: 99

Answers (1)

Prune
Prune

Reputation: 77837

Your problem is the infinite loop:

while Screen == "Title" and DB == 0:
    TTR = 'TitleScreenSmall.png'
    Raycast(0, 0)

Since the loop control variables Screen and DB never change, you have no way to exit the loop. You're stuck here, eternally repeating a function that does very little, and includes no changes to observe.

See this lovely debug blog for help.

Upvotes: 1

Related Questions