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?
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
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.
(http://i.imgur.com/IsoRyZr.png)
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.
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:
function closeMaps() {
gRansom.Visible=false;
gratmap.Visible=false;
}
function Bclose1_OnClick(GUIControl *control, MouseButton button) { closeMaps(); }
function Bclose2_OnClick(GUIControl *control, MouseButton button) { closeMaps(); }
Must admit I never thought of Gurok's solution... (roll)
I have however did this:
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)
Thanks