Is it possible to refer to a button by it's ID number?

Started by KodiakBehr, Sat 21/12/2013 02:18:20

Previous topic - Next topic

KodiakBehr

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

  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?

monkey0506

gui[].Controls[] is basically what you're looking for.

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


Alternately:

Code: ags
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;
}

KodiakBehr


SMF spam blocked by CleanTalk