DirectButton bind error

Sorry for my inexperience, I haven’t really used Panda3D or Python much before. I’m actually trying to modify some existing code. For some reason, whenever I try to bind a DirectButton such that a right mouse button executes a different command than a left mouse button, I get a runtime error that causes the program to exit immediately. Here’s what I’m working with now:

button_gotIt = DirectButton(frameSize=(-2.5,2.5,-0.5,1),pos=(-0.3,0,-0.65),text="Got it!", scale=.1, rolloverSound=None,clickSound=None,pressEffect=1)
button_gotIt.bind(DGG.B1PRESS, command = messenger.send, extraArgs=['a_got_it'])
button_gotIt.bind(DGG.B3PRESS, command = messenger.send, extraArgs=['b_got_it'])

If I do something like this, I’m fine:

button_gotItA = DirectButton(frameSize=(-2.5,2.5,-0.5,1),pos=(-0.8,0,-0.65),text="Got it!", scale=.1, commandButtons=[DGG.LMB], command=messenger.send, extraArgs=['a_got_it'],rolloverSound=None,clickSound=None,pressEffect=1)

However, that’s kind of limiting; ideally I’d like to only have one button with different methods for right and left mouse clicks. If anyone could help me with this, or even with some sort of equivalent of system pause so I could actually see what the error is, I’d greatly appreciate it.

What exactly is the runtime error you get?

The error I’m getting is:

File “C:\Panda3D-1.8.1.\direct\Task.py”, line 460, in step self.mgr.poll()
File “C:\Panda3D-1.8.1\direct\showbase\EventManager.py”, line 61, in eventLoopTask Self.doEvents()
File “C:\Panda3D-1.8.1\direct\showbase\EventManager.py”, line 55, in doEvents
processFunc(self.eventQueue.dequeueEvent())
File “C:\Panda3D-1.8.1\direct\showbase\EventManager.py”, line 122 in processEvent
Messenger.send(eventName, paramList)
File “C:\Panda3D-1.8.1\direct\showbase\Messenger.py”, line 397, in send self.__dispatch(acceptorDict, event, sentArgs, foundWatch)
File “C:\Panda3D-1.8.1\direct\showbase\Messenger.py”, line 482, in __dispatch method (*(extraArgs + sentArgs) )
File “C:\Panda3d-1.8.1\direct\showbase\Messenger.py”, line 397, in send self.__dispatch(acceptorDict, event, sentArgs. foundWatch)
File “C:\Panda3d-1.8.1\direct\showbase\Messenger.py”, line 482, in __dispatch method (*(extraArgs + sentArgs))
TypeError: can only concatenate list (not “libpanda.PGMouseWatcherParameter”) to list

Sorry again - this is probably something that I just didn’t catch because I’m not very familiar with Panda3D or Python yet.

Hmm, odd, seems some quirk related to how the extraArgs are appended. May I ask, though, why you are mapping the clicks to events - couldn’t you just map it directly to your event handler function?

If you need it to send an event for whatever reason, you could try something like this:

button_gotIt.bind(DGG.B1PRESS, command=lambda mouseParam: messenger.send('a_got_it'))

I’m not entirely sure why it was done this way, I’d need to ask the original developer. I thought it would be easier to modify the program I’m working on based on what already existed, but now I think I might want to do some modifications for efficiency and extensibility. I’ll try modifying the event handler as suggested.

Your code works perfectly as a quick fix in the meantime though.
Thanks!