0

I have a feeling this will have a very obvious answer but I am getting the above error. I tried putting parentheses to name the class but that did not fix the error.

Settings Module:

class Settings:
    def __init__(self):
        self.title = "Historic City Builder"


class Screen:
    def __init__(self):
        self.width = 1000
        self.height = 650


class Colors:
    def __init__(self):
        self.red = (255, 0, 0)
        self.green = (0, 255, 0)
        self.blue = (0, 0, 255)

        self.black = (0, 0, 0)
        self.white = (255, 255, 255)

Main:

import pygame as pg

from Settings import Settings
from Settings import Screen
from Settings import Colors

On = True

clock = pg.time.Clock()
pg.init()
MainDisplay = pg.display.set_mode((Screen.width, Screen.height))
pg.display.set_caption(Settings.title)

1 Answers1

0

You have not initialised your class, therefore __init__ has not run and set its variables as you have coded.

Try initlizing your class prior, that way it runs the __init__ block of code.

import pygame as pg

from Settings import Settings
from Settings import Screen
from Settings import Colors

On = True

clock = pg.time.Clock()
pg.init()
s = Screen() #Initialise the class Screen() as s
settings = Settings() #Init the class Settings() as settings
MainDisplay = pg.display.set_mode((s.width, s.height))
pg.display.set_caption(settings.title)

Here is some light reading to help;

self and __init__

PacketLoss
  • 5,561
  • 1
  • 9
  • 27