0

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

12
  • 1
    Do you receive any error message? Have you tried another pygame function where it worked? Commented Jan 24, 2019 at 20:23
  • Your given code has an infinite loop for me (after repairing the lack of a png file); no crash. Commented Jan 24, 2019 at 20:25
  • @Alex_P No, no error, and yes I have tried a few, but none work. Commented Jan 24, 2019 at 20:58
  • @Prune What does that mean exactly, It still does not work Commented Jan 24, 2019 at 21:00
  • @CyleLinin What did you not understand? I can't tell you "what does that mean" when I don't have a referent for "that". Commented Jan 24, 2019 at 21:06

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

2 Comments

Thank you, It works now, I guess I am stupid! :) "that was not a dis because I think you are smarter (which you are) I am just really dumb"
Been there, done that, have infinite t-shirts ... :-)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.