Msg Management

I’ve got a few newb question :slight_smile:

  1. how can i have an eventhandler that accept
    any message starting with “NET_”

  2. i would like to have an event handler that accept

but i got this error:
NameError: global name ‘msg’ is not defined
(msg is not defined in my class )

I’am a pure newb in python but python sounds pretty good …

Hi, Manakel.

  1. You can’t do that, but normally you wouldn’t need to–if you want to listen for a broad class of things happening, then just throw a generic event whenever you would have thrown a more specific event. You can throw both events at the same time if you like.

For instance:


And also:


Then you can just listen for the ‘NET’ event and you will get notified when either send_msg or recv_msg occurs.

  1. It looks like you are confusing the formal parameter list with the actual parameter list. You don’t repeat the formal parameters of your message handler on the accept function call; just give the function name. Something like this:

self.accept(‘NET_SEND_MSG’, self.handleMsg)

If you include a third parameter to the accept() function, it is a list of parameter values that will be passed to the self.handleMsg() function, in addition to those already sent by the messenger.send() call; the handler function must then have enough parameters in its formal parameter list to match all of the parameter values sent. In most cases, you don’t send any parameters.


Great. I found the first one but the second one was dizzing me…
Been too long as project manager and not coder