Couple of questions on this…
It seems that although this method is called on an event instance, it sets the callback for all instances of that event? I’m only ever getting the userdata that I passed into the most recent call to setCallback, regardless of which Event* the callback is firing on.
The docs suggest that "To avoid needing to process all messages simply switch on the messages you are interested in". How do I do this?
- nyoung asked 9 years ago
Bumping this – can anyone confirm that 1. is indeed the way that event callbacks work?
That is, that an event callback (and its userdata parameter) is set for the entire event, not for individual event instances (even though the method is called on an instance).
That would mean that if I call setCallBack on each event instance that I get, I’m actually overwriting each previous call to setCallBack for other instances of that event – and worse, if I set the callback to null for any event instance, I’m actually turning the callback off for all instances of that event.
Which is ok, because I can have per-instance callback behaviour by storing stuff in the instance’s userdata (that’s what I do now, and it works)… but the docs are not clear on this and the fact that you call the method on an event instance is confusing.
No, callback/userdata is definitely per event instance.
2. The docs suggest that "To avoid needing to process all messages simply switch on the messages you are interested in". How do I do this?
Use a switch statement.
Please login first to submit.