Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: EnterTheStory (aka tolworthy) on Tue 25/11/2008 16:31:54

Title: GUI buttons: how to tell what mouse click was used? (SOLVED)
Post by: EnterTheStory (aka tolworthy) on Tue 25/11/2008 16:31:54
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?
Title: Re: GUI buttons: how to tell what mouse click was used?
Post by: Dualnames on Tue 25/11/2008 17:47:07
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)
Title: Re: GUI buttons: how to tell what mouse click was used?
Post by: EnterTheStory (aka tolworthy) on Tue 25/11/2008 18:30:42
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.
Title: Re: GUI buttons: how to tell what mouse click was used?
Post by: Dualnames on Tue 25/11/2008 18:34:03
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//
}
Title: Re: GUI buttons: how to tell what mouse click was used?
Post by: Khris on Tue 25/11/2008 20:54:08
The code from Dualnames' first post will work perfectly fine with 2.72.