Python Forum
question about my pygame code for space shooter - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: Game Development (https://python-forum.io/forum-11.html)
+--- Thread: question about my pygame code for space shooter (/thread-36313.html)



question about my pygame code for space shooter - Than999 - Feb-07-2022

Hi, I am not sure why when I go and run my code I am getting these two errors:
Terminal Output:
"File "c:\Users\Timothy Han\Documents\Python Projects\Pygame\PygameForBeginners-main\Assets\Two_Player_Space_Shooter.py", line 18, in <module>
main()

File "c:\Users\Timothy Han\Documents\Python Projects\Pygame\PygameForBeginners-main\Assets\Two_Player_Space_Shooter.py", line 12, in main
if event.type == pygame.QUIT():
TypeError: 'int' object is not callable"

Also, the game window immediately opens and closes for some reason. I know that I set my while loop to 'True' until the player closes or exits out the game window. However, the game window automatically closes by itself real fast for some reason. Not sure why is that. Any suggestions or help would be greatly appreciated! Thanks!

import pygame 

WIDTH, HEIGHT = 900, 500
WIN = pygame.display.set_mode((WIDTH, HEIGHT))
pygame.display.set_caption("First Pygame!")

def main():

    done = True
    while done:
        for event in pygame.event.get():
            if event.type == pygame.QUIT():
                done = False
    
    pygame.quit()

if __name__ == "__main__":
    main()



game window immediately closesby itself and error in my code - Than999 - Feb-07-2022

Hi, I am not sure why when I go and run my code I am getting these two errors:
Terminal Output:
"File "c:\Users\Timothy Han\Documents\Python Projects\Pygame\PygameForBeginners-main\Assets\Two_Player_Space_Shooter.py", line 18, in <module>
main()

File "c:\Users\Timothy Han\Documents\Python Projects\Pygame\PygameForBeginners-main\Assets\Two_Player_Space_Shooter.py", line 12, in main
if event.type == pygame.QUIT():
TypeError: 'int' object is not callable"

Also, the game window immediately opens and closes for some reason. I know that I set my while loop to 'True' until the player closes or exits out the game window. However, the game window automatically closes by itself real fast for some reason. Not sure why is that. Any suggestions or help would be greatly appreciated! Thanks!

import pygame 

WIDTH, HEIGHT = 900, 500
WIN = pygame.display.set_mode((WIDTH, HEIGHT))
pygame.display.set_caption("First Pygame!")

def main():

    done = True
    while done:
        for event in pygame.event.get():
            if event.type == pygame.QUIT():
                done = False
    
    pygame.quit()

if __name__ == "__main__":
    main()



RE: game window immediately closesby itself and error in my code - BashBedlam - Feb-07-2022

pygame.QUITis an integer and you are trying to call it like a function or method with parentheses after it.
if event.type == pygame.QUIT():
should be...
if event.type == pygame.QUIT:



RE: question about my pygame code for space shooter - deanhystad - Feb-07-2022

1 error. 18 stops because of a problem in 12. Look up info about the pygame quit event.

The logic for the while loop starting in line 10 is also completely wrong. There are two errors cancelling each other out.


RE: question about my pygame code for space shooter - metulburr - Feb-07-2022

There are no parentheses on QUIT