PDA

View Full Version : EventClass used with multiple joysticks


tokola
11-30-2012, 10:45 AM
Hi there.

I have been struggling to make multiple events with multiple joysticks but it seems the last event always supersedes the previous ones. I have used EventClass to do, taken as an example the EventHandlingClass tutorial, but I am obviously doing something wrong. My code is as follows:
class Joystick(viz.EventClass):
"""This is the Joystick Interacion class"""
def __init__ (self, window):
self.joystick = vizjoy.add()
#Call super class constructor
viz.EventClass.__init__(self)
self.window = window
self.callback(vizjoy.BUTTONDOWN_EVENT, self.joydown)
self.callback(vizjoy.HAT_EVENT, self.joyhat)
and create two joysticks like this:

j2 = Interaction.Joystick(somewindow1)
j3 = Interaction.Joystick(somewindow2)
but every time I use the hat (D-pad) or click a button, both of my windows respond to this event. What am I doing wrong?

farshizzo
11-30-2012, 12:04 PM
Can you post the code for your callback functions? Within the callback functions, are you checking that the event was generated for the correct joystick object (e.joy is self.joystick)?

tokola
11-30-2012, 12:51 PM
Truth is I wasn't doing that, but why should this matter since the EventClass instance of each Interaction object has it's own callbacks? Isn't this the purpose of EventClass after all, to be able to assign different callback functions for the same event?

For future reference of anyone visiting this thread, putting the following check at the beginning of each callback function fixed the problem:
if e.joy != self.joystick:
return
Thanks a lot!