how to messenger.send trigger many function from one key?

is it possible to trigger 2 or more function with the same key?


and then when i send enter key, both function will react.
by default only the last assigned function (func2) will be triggered.

Thanks in advance.

You could just have your function call other functions.

base.accept("enter", func)
def func():

In case of OOP, just be sure to use separate listeners :

DO1 = DirectObject()
DO2 = DirectObject()


That’s a good solution but when the code is growing larger you don’t even know where the function will be created. Besides in OOP it’s impossible to pass every variable into every functions created.

i haven’t figure it out using another DirectObject, currently i’m using only one of it and everything works normal.
The only way that i’ve found so far is using a tricky way, injecting into the _messengerId, which is:


it works but the result is uncertain. :stuck_out_tongue:

Is that true? or is there any other similar workaround?

then you should NOT abuse base. Create its own DO.

I’ll figure some other way out when major problem occured because of it.
Besides more object means more resources spent.

Currently my solution works fine, even the implementation looks odd :smiley:

I think i should learn a bit about DO, i haven’t figured that out from the sample programs. Is base is the implementation of DO itself? I should discover the scope first :wink:

I would just use massager.accept instead

I think setting object to None allows you to define many handles other wise just crate object() it only cares about ID any ways.

I’ll try that one.


Finally i’ve got the answer of my own question.

First, don’t try my late solution, changing base._messengerId=(‘ShowBase’,‘unique_id’) will result many flaws, sometimes it works perfectly but in other case it may got jammed.

After reading this thread:
[url]Panda's event handling...]
i’ve got these conclusions:

  • DirectObject need to be created for creating an unique messenger acceptation (i’ve never use it before though, and don’t understand why it should be there, besides the implementation looks odd)

  • The only purpose to reassign the DirectObject in each class i’ve found so far is just to create an unique id of each messenger accept… what a waste.

  • messenger is one of the best and the most usefull function in panda, it allows developer to communicate each object without passing variables to each other. Thus i really really recommend this one to be perfected.

  • if it only about the id then why not find another workaround, there are many ways to do the uniqueness, maybe like this:
    if unique_id is not present then the old dictionary will be replaced,
    while if different unique_id assigned then it will create a new acceptation list.

  • and i recommend using just the base, one for all, all for all, why not, besides it will simplify user’s logic anyway.

Why is it wasteful to inherit from DirectObject?

Well the only purpose inheriting the DO that i’ve found so far is only for the messenger.accept

Don’t know if there’s another purpose yet :slight_smile:

It’s a waste of procedure.

In the other hand, it create some ambiguity about how each DO connect each other.
Maybe in my case like the CollisionTraverser that is created inside the class object, say:


with another class object


we create different Collision Traverser but they implement the same self.accept in DO, which is triggered from the addIn/OutPattern.

Then a newbie will almost likely got confused while accepting the pattern from different object. Is it still related or not?

And the other bad side of implementing DO per class object is that we unable create 2 output function from one trigger key in the same class. ex:


only one of them will be executed in the same class.
why not just release the messenger into a global function, then we don’t have to bother about variables scoping, as i recommend before, what if we just use base.accept() …
we send it, then everywhere will accept if it is well determined.

hmmm kinda hard to explain this in english, hope you get it though :stuck_out_tongue: