Too many positional arguments for function call error

Viewed 48

I am using visual studio code and I am practicing the book python crash course but when I run the code it give me three problem. I made screen print to show my problem clearly

  • 1- Too many positional argument for function call pylint
  • 2- (function) run_game NotReturn
  • 3- TypeError check – events() take 0 positional argument but 1 was given
import sys
import pygame
from settings import Settings
from ship import Ship
import game_functions as gf

def run_game():
    #initialize game and create a screen object.
    ai_settings = Settings()
    screen = pygame.display.set_mode((ai_settings.screen_width, 
    ai_settings.screen_height))
    pygame.display.set_mode((1200, 800))
    pygame.display.set_caption("Alein Invasion")

    #Make a ship.
    ship= Ship(screen)
    #set the background color.
    bgcolor=(230,230,230)

    #start the main loop for the game.
    while True:
        gf.check_events(ship)
        ship.update()
        gf.update_screen(ai_settings,screen,ship)

        #Redraw the screen during each pass through the loop.
        screen.fill(ai_settings.bg_color)
        ship.blitme()

        #make the most recently drawn screen visible.
        pygame.display.flip()
        run_game()

Output:

  line 27, in <module>
    run_game()
  File 
  "c:\Users\naema\OneDrive\Desktop\python_work\alien_invasion.py", 
   line 18, in run_game
    gf.check_events(ship)
    TypeError: check_events() takes 0 positional arguments but 1 was given

PS C:\Users\naema\OneDrive\Desktop\python_work>enter code here

1 Answers

Your posted output tells us, that the function check_events() doesn't take any arguments but you provided one, ship. From what I found online about game_functions, it should look like this:

import sys,pygame

def check_events(ship):
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            sys.exit()
...

Which would be in line with your current main loop. Did you remove its argument ship? This is most likely the cause of your problem.

Related