using the "object.runFunc = def()" command

My game consists of 12 cards face down on a table, and each card corresponds to a scene. I am creating the scene instance inside the constructor of the card class since each card has exactly one corresponding scene. Each scene is just a big model with the camera moving around, and some sounds playing, but each scene is different.

Basically when I instantiate each scene, I want to define a function in that instance called “runFunc” that will contain the sequence of intervals needed for camera movement and sound.

Each scene has a starting camera location which I will know in advance. So my instantiation would look something like this:

newScene = Scene(sceneNum, sceneStartDummyNode)
newScene.runFunc = def():
    #insert details of instance function here

I found out I could do this from my instructor, but he was a little fuzzy on the syntax. I just wanted to make sure this was correct.

Also, do I have to define the runFunc function in advance in the scene class like this:

def runFunc(self, num, startNode):

or does the newScene.runFunc = def() define the function for me?

Thanks in advance,


Haven’t really heard of it and when I tried it, it threw a syntax error (in python 2.2). You probably dont want to edit the attributes of a Scene instance anyway. Try making a new class that inherits from Scene and define a dummy runFunc method. Then define functions that you can later assign runFunc to.

class ParentClass:
    def __init__(self):
        self.x = 1
#end class

class c(ParentClass):

    def __init__(self):
        self.a1 = 0
        self.a2 = 0

    def func(self, arg1, arg2):
        #dummy function that will be defined later

    def pprint(self):
        print self.a1, self.a2
#end class

def f1(self, arg1, arg2):
    self.a1 = arg1
    self.a2 = arg2
    print "function 1"
#end def

def f2(self, arg1, arg2):
    self.a1 = arg1
    self.a2 = arg2
    print "function 2"
#end def

instance1 = c()
instance1.func = f1

instance1.func(instance1, 1, 2)

instance2 = c()
instance2.func = f2

instance2.func(instance2, 3, 4)