so I have two files: main.py and settings.py
I am trying to import everything from settings.py into main.py using from settings import *
It just returns this error:
Traceback (most recent call last): File "d:\Programming\3DGAME\main.py", line 37, in <module> game = Game() ^^^^^^ File "d:\Programming\3DGAME\main.py", line 10, in __init__ self.screen = pg.display.set_mode(RES) ^^^NameError: name 'RES' is not defined
this is main.py:
import pygame as pgimport sysfrom settings import *class Game: def __init__(self): pg.init() self.screen = pg.display.set_mode(RES) self.clock = pg.time.Clock() def new_game(self): pass def update(self): pg.display.flip() self.clock.tick(fps) pg.display.set_caption(f'{self.clock.get_fps() :.1f}') def draw(self): self.screen.fill('black') def check_events(self): for event in pg.event.get(): if event.type == pg.QUIT or (event.type == pg.KEYDOWN and event.key == pg.K_ESCAPE): pg.quit() sys.quit() def run(self): while True: self.check_events() self.update() self.draw()if __name__ == '__main__': game = Game() game.run()
this is settings.py:
RES = WIDTH, HEIGHT = 1600, 900fps = 60
It only works if I transfer the vars into main.py. I also tried to ask for specific vars like: from settings import RES. still no work smh