2

I'm fairly new to python. I'm writing a code for a simple alien invasion game but I'm getting this error.

import sys
import pygame
from settings import Settings
from ship import Ship
import game_functions as gf

def run_game():
    pygame.init()
    ai_settings = Settings()
    screen = pygame.display.set_mode((ai_settings.screen_width, ai_settings.screen_height))
    pygame.display.set_caption("Game")
    ship = Ship(screen)
    bg_color = (230, 230, 230)

    while True:
        gf.check_events(ship)
        ship.update()
        gf.update_screen(ai_settings, screen, ship)
        for event in pygame.event.get():
            if event.type==pygame.QUIT():
                sys.exit()
        screen.fill(ai_settings.bg_color)
        ship.blitme()
        pygame.display.flip()
run_game()

I'm aware that I'm accidentally calling some integer value but I have no clue where I'm going wrong.

I have also checked these lines

File "C:/Users/Areeb Irfan/.PyCharmCE2018.3/config/scratches/AlienGame.py", line 25, in run_game()
File "C:/Users/Areeb Irfan/.PyCharmCE2018.3/config/scratches/AlienGame.py", line 16, in run_game gf.check_events(ship)
File "C:\Users\Areeb Irfan.PyCharmCE2018.3\config\scratches\game_functions.py", line 5, in check_events if event.type==pygame.QUIT():
TypeError: 'int' object is not callable

6
  • I have used 3 more modules named game_functions, ship, settings. Commented Jul 21, 2019 at 18:11
  • you have clue in error message - it shows you line with problem. If you see word "collable" then you have problem with () Commented Jul 21, 2019 at 18:12
  • 2
    pygame.QUIT is integer value, not function. You can't use () with pygame.QUIT Commented Jul 21, 2019 at 18:13
  • 6
    Replace event.type==pygame.QUIT() with event.type==pygame.QUIT Commented Jul 21, 2019 at 18:13
  • 1
    You can see this by the way in the last line of the traceback. Commented Jul 21, 2019 at 18:16

3 Answers 3

4

As shown in your error message, this line event.type==pygame.QUIT() is the issue. The error TypeError: 'int' object is not callable means that you are trying to call an int, which means that you are trying to treat an int as a function, which in turn means that you have parentheses () after an int value. The only place you have parentheses in that line is afer pygame.QUIT, so just remove the parentheses:

if event.type==pygame.QUIT:
Sign up to request clarification or add additional context in comments.

Comments

0

To fix that, remove the parentheses () at pygame.QUIT. Get rid of them, and run the code again. It should work, as long as you don't have that same "if" somewhere else.

1 Comment

From what I can tell, you are saying the same thing as the previous answer. Maybe edit to clarify how yours is different?
0

There is a flaw in your code. You have written as:

if event.type == pygame.QUIT():
        quit()

Better try using this code:

if event.type == pygame.QUIT():
        quit()

(or)

if event.type == pygame.QUIT():
        sys.exit()

This happens because pygame.QUIT is an integer data. Integer data is not followed by parantheses. But enclosing it with parantheses makes it to be a function which is wrong. Hope this helps you!

Comments

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.