Methods of level loading in Panda3d (Solved)

I’m not quite sure of what you’re trying to do that might be a problem for classes. Classes can be instantiated multiple times without trouble–something like this, given a class named “MyClass”:

def someFunction():
    myInstance1 = MyClass(<parameters, if any>)
    myInstance2 = MyClass(<parameters, if any>)

We then have two instances of the same class.

(They’ll be lost once the function exits, of course, but you already know about that. I’m just giving a very simple example of instantiating two instances of a class.)

You don’t need to, if I’m not much mistaken: “loader” is a global variable, and should be available without a reference like “self”.

However, in general, “self” is in essence just another parameter, like any other passed to a function or method. It doesn’t even have to be named “self”, if I’m not much mistaken. It just happens to be one that’s (usually) automatically filled in by Python for you, providing a reference to the class to which the method belongs.

As to getting access to the main object that you’re using, you can just pass in a reference to it like any other parameter.

For example, let’s say that your “main class” is called “Game”, and we’ll stick to the name of your “Room” class. Then we might have something like this:

class Game():
    def __init__(self, <other parameters, if called for):
        # Initialisation here

    def someFunctionThatAccessesRoom(self, <parameters, if called for>):
        # Perhaps this is your task, perhaps it's something else; it shouldn't matter
        # Since this method belongs to "Game", "self" here will refer to the
        # instance of "Game" to which it belongs
        someRoomObject.someRoomFunction(self)

class Room():
    def __init__(self, <parameters, if called for>):
        # Initialisation here

    def someRoomFunction(self, game):
        # Note that the game is the >second< parameter here. As always, the first
        # parameter to an instance function, here called "self", is automatically
        # filled in by Python with a reference to the instance--in this case a reference
        # to the instance of the "Room" class associated with this call. Any parameters
        # passed in manually, as the "Game" instance was above, follow after that.
        self.someVariable = game.someOtherVariable

All of that said, you may find this a little awkward at times. In that case, you may find it worthwhile to create a “common” object or file that can be included in any other, and give access to frequently-used objects, like the game, or the current level.