Help counting mouse clicks in jit.pwindow to perform different actions

Valery_Kondakoff's icon

Hello!

I'm trying to draw a line using jit.mgraphics by clicking with my mouse inside jit.pwindow. The problem is that I need to draw different things on the first mouse click (ellipse) and the rest of the clicks (line + ellipse). So, I decided to count the clicks.
Here is my attempt to do this:

Max Patch
Copy patch and select New From Clipboard in Max.

It works but the code is _very_ not elegant, so I'm pretty sure I missed a proper way to implement this. Any suggestions?

Thank you!

Vincent Goudard's icon

Not sure it makes it very much more elegant, but here a more minimal version, not using counter

Max Patch
Copy patch and select New From Clipboard in Max.

Valery_Kondakoff's icon

Hello, Vincent! Thanks for help! Unfortunately your example does not work correctly on my system: both messages to jit.mgraphics are fired every mouse click. There is a night around here, I will try to look closer to your code tomorrow.

Valery_Kondakoff's icon

Here is another one attempt, using your ideas, Vincent:

Max Patch
Copy patch and select New From Clipboard in Max.