Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: KodiakBehr on Sat 21/12/2013 02:18:20

Title: Is it possible to refer to a button by it's ID number?
Post by: KodiakBehr on Sat 21/12/2013 02:18:20
I've got buttons that are tied to characters that are being called by their ID numbers.  Is there a way I can single them out other than by their name?

A hypothetical example:

Code (ags) Select

  if (gvcommand=="Operation One"){
      character[selection].Walk(582, 176, eNoBlock, eWalkableAreas);
      btnCrew1.NormalGraphic=106;
      }


I want "btnCrew1" to instead refer to the button that has the ID number of "selection".  Is there a command to do this?
Title: Re: Is it possible to refer to a button by it's ID number?
Post by: monkey0506 on Sat 21/12/2013 02:31:54
gui[].Controls[] is basically what you're looking for.

Code (ags) Select
if (selection < gSpecificGUI.ControlCount)
{
  Button *selectionButton = gSpecificGUI.Controls[selection].AsButton;
  if (selectionButton != null) selectionButton.NormalGraphic = 106;
}


Alternately:

Code (ags) Select
GUI *selectionGUI = gui[SOME_GUI_ID_OR_USER_SELECTION];
if (selection < selectionGUI.ControlCount)
{
  Button *selectionButton = selectionGUI.Controls[selection].AsButton;
  if (selectionButton != null) selectionButton.NormalGraphic = 106;
}
Title: Re: Is it possible to refer to a button by it's ID number?
Post by: KodiakBehr on Sat 21/12/2013 15:32:05
Perfect.  Many thanks!