Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Knox on Tue 05/04/2011 17:17:04

Title: Adding a new parameter into an _OnClick function **SOLVED**
Post by: Knox on Tue 05/04/2011 17:17:04

function btnQuickGuide_PrevPg_OnClick(GUIControl *control, MouseButton button, int iMode)
{
 if (iMode == 0)...stuff;
 else ...stuff;
}


There's no problem using the above code when I call the _OnClick manually (via a key press, for example), but when I click the actual button that has this code, how do I set iMode? Where should it be placed?


Called from inside a key press: btnQuickGuide_PrevPg_OnClick(btnQuickGuideVC_PrevPg, eMouseLeft, 1);


When a key is pressed, that function will always be mode 1, if the button of the gui is clicked on, it will always be mode 0.

(*I guess I could make 2 separate functions, one for the key press, one for the click, but Id rather not duplicate code).
Title: Re: Adding a new parameter into an _OnClick function
Post by: monkey0506 on Tue 05/04/2011 22:41:43
You don't necessarily need to duplicate code, but since AGS doesn't allow functions to be overloaded (meaning, multiple functions with the same name but different parameter lists), you can't link your events to functions that have different parameter lists than what the event itself requires.

What you could do is:

function btnQuickGuide_PrevPg_OnClickHandler(GUIControl *control, MouseButton button, int iMode)
{
  if (iMode == 0)
  {
    // ..stuff..
  }
  else
  {
    // ..other stuff..
  }
}

function btnQuickGuide_PrevPg_OnClick(GUIControl *control, MouseButton button)
{
  btnQuickGuide_PrevPg_OnClickHandler(control, button, 0);
}


Then you would call the OnClickHandler function yourself, and let AGS call the normal OnClick function. It's a little bit more than your original line of thinking, but this is pretty much the method you'd need even if overloading was allowed.
Title: Re: Adding a new parameter into an _OnClick function
Post by: Knox on Tue 05/04/2011 23:40:05
holy sheet. Ingenious!

Ill get right to it, good news is now I can reuse this in other places too :)