Working on a simple python game


#1

I’m working through a python project where we are developing a space invader type game… I’m hung on an error I’m getting. Can’t seem to find where the issue is.

When running the game I get a no Settings instance has no attribute ‘screen_width’

However, I’ve checked spelling and white spaces side by side. still get the same error. The game worked fine up until this point so I’m certain this bit of code is where the bug lies.

settings.py

class Settings():
   def _init_(self):
        self.screen_width = 1200
        self.screen_height = 800
        self.bg_color = (230, 230, 230)

Alien Invasion.py

import pygame
from settings import Settings

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("Alien Invasion")

Thanks in advance
Devin!


#2

Also, this is Python 2.7


#3

It should be __init()__ and not _init()_ :slight_smile: