My assignment is to make a game, were supposed to have multiple modules to avoid clutter in one script. I'm having an issue with import a variable from one of the modules. So far I have a settings one, and a main one. The settings is pretty simple and goes:
class Settings():
def __init__(self):
self.screen_width = 1920
self.screen_height = 1080
self.bg_color = (230, 230, 230)
Pretty simple, yet when I try to reference these variables it says "Unresolved attribute reference 'screen_width' for class 'Settings'
main goes as this:
import sys, pygame
from game_settings import Settings
def run_game():
#Initialize the game and create the window
pygame.init()
screen = pygame.display.set_mode((Settings.screen_width,Settings.screen_height), pygame.FULLSCREEN)
pygame.display.set_caption("Alien Invasion")
while True:
#Listening for events
for event in pygame.event.get():
if event.type == pygame.QUIT:
sys.exit()
screen.fill(Settings.bg_color)
pygame.display.flip()
run_game()
I thought maybe this would be a PyCharm issue, but found that it does the same thing in IDLE so what would be the correct way to import the variables?
Thanks for taking the time to read this!
bg_color,screen_widthandscree_heightpart of the instances rather than the class itself? In other words, I dont think you can just access Settings.bg_color, I think you need to make a Settings object likes = Settings()and then you can dos.bg_color.