[SOLVED] "On_Click" GUI Function

Started by Fekix, Wed 31/08/2005 01:24:25

Previous topic - Next topic

Fekix

Hello,

i'm wondering how the On Click Function for GUIs works. I didn't find a documentation in the Help file for this Option.
I figured out that there are two Integers which will be passed to the Function but I don't know what they do. One is possible for the Mouse Button clicked on the GUI but the second??

Maybe you can help meÃ,  ;)

Thanks
Felix

P.S.

To make it more understandable:

function gGUIName_Click(int Integer1, int Integer2) {
Ã,  //some code here
}

This function works fine but I have to give the Function the 2 Integers (Integer1 and Integer2 in this example) otherwise AGS will throw an Error when clicking the GUI
Currently working on: My Little Real Life Adventure

strazer

The function header looks like this:

function gGuiname_Click(GUI *theGui, MouseButton button) {

Unless you want to call it manually, you don't have to pass any parameters.
The function is called by AGS in the event that the GUI is clicked, and the parameters are passed to it automatically:

The first parameter is a pointer to the GUI that was clicked (that the function belongs to) so you can access it from within this function. For example:

  theGui.Visible = false;

The second parameter holds which mouse button has been clicked on the GUI. So you could do for example:

  if (button == eMouseRight) theGui.Visible = false;

--

If you really must call this function manually (not recommended), you have to pass proper parameters like this:

gGuiname_Click(gGuiname, eMouseRight);

Keep in mind that a called function must be positioned in the script before the line where you call it.

While calling these in-built functions directly works fine, it is not recommended, so better do it like this:

Code: ags

function DoMyStuff() {
  Display("The stuff!");
}

function gGuiname_Click(GUI *theGui, MouseButton button) {
  DoMyStuff();
}

function SomeOtherFunction() {
  DoMyStuff(); // instead of calling the _Click function above
}

Fekix

thank you  :)

i don't want to call the function manually but i didn't know which two integers were passed to the function when clicking the gui.
Currently working on: My Little Real Life Adventure

Pumaman

The function definition should be created automatically by the editor, why did you need to define them yourself?

monkey0506

When it is created manually the first parameter is a pointer to a GUIControl...not a GUI. :=

Just FYI.

strazer

What do you mean? The example above is for a click on a GUI, not a GUI Control.

For GUI Control click functions, the first parameter is the pointer to the GUI Control that was clicked, true.

monkey0506

Oops...I should read more thoroughly...But ATM I don't really care...I'm not in the mood to care...

:-[

SMF spam blocked by CleanTalk