GUI Control mouse click question

Started by Newbie Newt, Thu 06/10/2016 23:14:24

Previous topic - Next topic

Newbie Newt

I have a couple of maps(GUIs) with "close" buttons. Both GUIs perform the same function when the "close" button is clicked. Is there a way to include both button 1 & button 2 in the same mouseclick function?
Code: ags

function Bclose2_OnClick(GUIControl *control, MouseButton button)
{
  gRansom.Visible=false;
  gratmap.Visible=false;
  gRansom.Visible=false;
  gratmap.Visible=false;
}


I tried the following, but I knew it wouldn't work.
function Bclose2_OnClick || Bclose1_OnClick (GUIControl *control, MouseButton button)

Thanks

Gurok

#1
Yes, there's a way. Go to the events tab of the properties for each button and change the OnClick binding of both buttons to the same function. It's a free text field.



You might even want to call the function Bclose_OnClick, as it applies to both Bclose buttons.

Note: It seems odd to me that you're setting the Visible property of those GUIs twice.
[img]http://7d4iqnx.gif;rWRLUuw.gi

Khris

Just for reference, this is the reason why the GUIControl that was clicked is passed into the function.
You can for instance create a keypad GUI with ten buttons and handle all ten of them using a single function. To find out which of the ten buttons was clicked, you simply check control.ID.

Also note that if AGS didn't allow to freely assign handler functions to events, one could still do this:
Code: ags
function closeMaps() {
  gRansom.Visible=false;
  gratmap.Visible=false;
}

function Bclose1_OnClick(GUIControl *control, MouseButton button) { closeMaps(); }
function Bclose2_OnClick(GUIControl *control, MouseButton button) { closeMaps(); }

Cassiebsg

Must admit I never thought of Gurok's solution... (roll)

I have however did this:
Code: ags

function something()
{
...
}

function something_else();
{
something();
}


Works just fine, but I'm pretty sure I'll be using Gurok's solution from now on... saves so much code on the script. (laugh)
There are those who believe that life here began out there...


SMF spam blocked by CleanTalk