Accept execution order

Hi all,

I’ve got an issue where I need a set of messages “bookended” by another set of messages. For example consider the following:

class Foo( DirectObject ):
    def __init__( self, arg ):
        DirectObject.__init__( self )
        self.arg = arg
    def OnDown( self ):
        print 'Down ', self.arg
    def OnUp( self ):
        print 'Up ', self.arg

self.foo1 = Foo( '1' )
self.foo2 = Foo( '2' )
self.foo2.accept( 'mouse1', self.foo2.OnDown )
self.foo1.accept( 'mouse1', self.foo1.OnDown )

self.foo1.accept( 'mouse1-up', self.foo1.OnUp )
self.foo2.accept( 'mouse1-up', self.foo2.OnUp )

I would expect the following code to produce the output:

Down  2
Down  1
Up  1
Up  2

but it doesn’t - I get:

Down  1
Down  2
Up  1
Up  2

Is there any way to force the order in which accept messages are executed?

Why would you expect that output? The accept method just tells the game to do something when it sees a button is pressed later on. There’s no way to order that by what order you call the methods, especially not when the accept()s are being called on completely different classes.

You’ll probably have to write your own class to store the events and then run a task to order them how you want before calling the methods.

But I’m more confused as to why you need to do this at all? Couldn’t you just have a single DirectObject class that controls all events? You would then control the order of the methods in a wrapper method passed to the DirectObject. E.g. you would do something like this

class Controller(DirectObject):

def mouse1down():

def mouse1up():

c = Controller()

But obviously mouse1down and mouse1up would be methods of a relevant class.

edit: typos/grammar

Thanks for your answer, Tober. I guess I thought accept worked like tasks do where they have priority of execution. I was trying to wrap a module which has its own accept calls and was hoping not to have to restructure anything. Yours is the simplest solution however.