Im preparing myself to exercise 45, where I have to create my own game.
I was thinking to structure the game in a way so all my rooms are in a separate fil - Rooms.py.
However I can’t seem to get it work properly, or maybe it’s me who don’t understand it right.
I have my main code:
import Rooms
class Main(object):
def __init__(self):
self.Rooms = Rooms
def mainClassTest(self):
self.Rooms.Second.SecondClassTxt()
def mainFunctionTest(self):
self.Rooms.SecondFunctionTxt()
who=Main()
who.mainClassTest()
who.mainFunctionTest()
And I have my second code called Rooms.py - in same folder with the following:
class Second(object):
def SecondClassTxt(self):
print('SecondClassTxt')
def SecondFunctionTxt():
print('SecondFunctionTxt')
My problem is I can get the SecondFunctionTxt() function to run, but I can’t get the method to run inside the ‘Second’ class.
I get the following error:
self.Rooms.Second.SecondClassTxt()
TypeError: SecondClassTxt() missing 1 required positional argument: ‘self’
I can see how I can just make a bunch of function for all my rooms and be done with it, but shouldn’t I also be able to access classes from my main code?