I kinda already posted this once in someone elses thread (sry), but no one responded and 3 days of many hours of searching (yeah, i feel pretty retarded right now) I still don’t have a working answer.
My question has to do with class instance scope in other modules, and is pretty much just a python thing. Essentially, I have several controller/manager classes, all created in one file. Later in the program, I have other classes (defined in another file) that need direct access to the controller class (usually its just a method call, but the data is “administrative” level and I have to manipulate only one set of data).
here’s a concatenated concept of what I am trying to do…and thus is probably useless ^^
file: main.py
import SpawnController
import FloorController
class main():
def __init__(self):
SPAWNCTR = SpawnController.SpawnController()
FLOORCTR = FloorController.FloorController()
FLOORCTR.newLevel()
...
file: FloorController.py
import Floor
class FloorController():
...
def newLevel(self):
self.currentFloor = Floor()
...
file: Floor.py
class Floor():
def __init__(self):
#self.model = loader.loadModel("floor1")
self.createSpawnPoints()
...
def createSpawnPoints():
SPAWNCTR.createSP()
...
file: SpawnController.py
class SpawnController():
...
def createSP(self):
print "create spawn point" #not really necessary
its the same concept as the factory design pattern…except anyone and everyone needs to have access to the factories. Also, there is kinda also some circular dependencies (at least thats what i get from asking other people…).
I’ve tried using the global statements, but I must be doing something wrong because it did nothing. I tried passing in the needed controller objects as parameters, but not only was it a mess, none of the changes made stayed without reverting back to default at some point.
I was wondering if there was a way to declare these upper level classes so the other classes have access…like the c++ equivelant to global, extern, and static jumbled together (or kinda like the “base” instance in panda)? If not that (or if its just a plain bad idea), how should I go about that kind of functionality? I figure this is a fairly common thing with large projects, so someone has to know how to best go about implementation of manager classes.
thanks,
~Silver~
**EDIT-- I’ve updated the code so that you should be able to use it as is (minus the elipses) and see my problem.