Manager instance scope resolution...

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.

Your pseudo code does not help. What are you trying to do ? Can you make it more direct to illustrate the circular dependencies ?

You also can check on ShowBase.py to see if any technique you can borrow.

I personally don’t see any circulatory dependencies; when I explain my problem to others, some of them say that type of implementation is likely to have circulatory dependencies…but I don’t fully understand what that means.

What I’m trying to do: in my main file I create instances of several manager objects, for this example I used by spawning and level generator controllers (for this instance assume floor = level). When I create a new level I have to generate spawn points, which is done through the spawn controller interface (oop, forgot to put the new level line in the code). The problem is that the creation of the level requires access to the instance of the spawn controller object from the main file but is apparently out of scope. As the use of managers is pretty heavy in our project implementation, I need to either find a way to resolve this scope issue correctly or redesign our entire class hierarchy/methodology.

so SPAWNMGR is a global in main.py ?

If so, you can always access it as:

import main
main.SPAWNMGR.createSP()

Isn’t it ?

Ok, I figured out what I was doing wrong. First, I didn’t know I had to declare it global, as I tried that before and that didn’t work right. Also, I realized that I couldn’t create the program instance of the main class at the end of the file as that would cause (what I assume) the circular dependency thing (it was doing some weird stuff to the imports having them loop around). I’m still working the bugs out, but now it looks like I can access my managers now. Sorry for the stupid questions.

~Silver~