Global Mouse Position in JSUI
You forgot to actually save the mouse position when clicked. Just add
mouse_state(x,y);
at the end of your function onclick();
But mouseClickX and mouseClickY only save the initial position of the cursor relatively to the jsui itself. So in order to be able to set the cursor position in absolute screen coordinates, you need to add the position of the patch window in the screen, and the position of the jsui in the patch, .
So replace your
max.pupdate(mouseClickX, mouseClickY)
by
max.pupdate(mouseClickX + box.rect[0] + patcher.wind.location[0], mouseClickY + box.rect[1] + patcher.wind.location[1]);
But then you'll notice that the mouse is still a little bit offset when you release the click. This is because of the toolbars. Either disable it (untick Toolbar in the View menu) or add an X and Y offset of the size of the toolbar (around 30px I guess). I guess you can also programmatically check if the toolba is enabled or not and automatically add or not the offset.
Beside that, I saw various weird stuff in your code, I just ignored it.
that fixed my problem
Great thanks! XOXO