GUI buttons: how to tell what mouse click was used? (SOLVED)

Started by EnterTheStory (aka tolworthy), Tue 25/11/2008 16:31:54

Previous topic - Next topic

EnterTheStory (aka tolworthy)

I want to make a GUI button behave differently, depending on if it's the left or right mouse that called it. I tried mouse.IsButtonDown(eMouseLeft) but that doesn't work (I'm guessing because the button is triggered by the mouse being released).

Do I need to use repExAlways and constantly check if the mouse is pressed over a button? Or is there a simpler way?

Dualnames

Ok, we all probably got stuck with a similar problem, so nevermind.
At the button you have created (let's name it's script name as Button1).

Put this on the button's interaction.

if (button==eMouseLeft) {
//code//
}
if (button==eMouseRight) {
//code//
}

(I'm assuming you're using AGS 3.0 and higher)
Worked on Strangeland, Primordia, Hob's Barrow, The Cat Lady, Mage's Initiation, Until I Have You, Downfall, Hunie Pop, and every game in the Wadjet Eye Games catalogue (porting)

EnterTheStory (aka tolworthy)

Quote from: Dualnames on Tue 25/11/2008 17:47:07
(I'm assuming you're using AGS 3.0 and higher)
That explains it. I saw the 'button ==' code in other threads, but it doesn't compile in 2.72 (which I use for Linux compatibility).

I have a compromise where RepExAlways constantly updates 'lastMouseButtonClicked' and the GUI button code looks at that. It seems to work, but I wondered if there was a solution that could be completely contained within the GUI button.

Dualnames

Oh, shit, I just saw it was you. I was aware you're using AGS 2.72..Ok, so..
Well, there's a way, probably not a one definetely working but it might as well.
Ok go to the global script header and add this:
bool rightclicked=false;

At the on_mouse_click section put something like this:
if (button==eMouseRight) {
rightclicked=true;
}
else {
rightclicked=false;
}

then at the buttons function part put this:
if (rightclicked==true) {
//code//
}
Worked on Strangeland, Primordia, Hob's Barrow, The Cat Lady, Mage's Initiation, Until I Have You, Downfall, Hunie Pop, and every game in the Wadjet Eye Games catalogue (porting)

Khris

The code from Dualnames' first post will work perfectly fine with 2.72.

SMF spam blocked by CleanTalk