Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: hedgefield on Tue 07/06/2011 21:05:52

Title: Bulk process a set of buttons? [SOLVED]
Post by: hedgefield on Tue 07/06/2011 21:05:52
Hey guys, quick question - is there a way to loop through a list of GUI buttons?
I wanna change one property on 18 different buttons at once, and instead of copy-pasting like a chump I thought maybe there's a more efficient way, maybe constructing a while-loop akin to:

int number = 1;
while (number < 18) {
 Button[number].TextColor = 15;
 number += 1;
}

Except I don't think the Button type supports that kind of modularity. I looked at using the button ID but I couldn't figure out how to use that. Might have missed something in the manual, I'm not too knowledgeable about the tricky stuff like structs, arrays and pointers.
Title: Re: Bulk process a set of buttons?
Post by: monkey0506 on Tue 07/06/2011 21:21:16
Are the buttons all on the same GUI and sequentially ordered? If so:

int i = FIRST_BUTTON_ID;
while (i < (FIRST_BUTTON_ID + 18))
{
  gOwningGUI.Controls[i].AsButton.TextColor = 15;
  i++;
}


Is there perhaps one button per GUI across 18 GUIs, each with the same ID? (I do realize this is significantly less likely) If so:

int i = FIRST_GUI_ID;
while (i < (FIRST_GUI_ID + 18))
{
  gui[i].Controls[BUTTON_ID].AsButton.TextColor = 15;
  i++;
}


If neither of the above apply, are you changing the text color of all of the buttons on all of the GUIs in your game? If so:

int g = 0;
while (g < Game.GUICount)
{
  int c = 0;
  while (c < gui[g].ControlCount)
  {
    if (gui[g].Controls[c].AsButton != null) gui[g].Controls[c].AsButton.TextColor = 15;
    c++; // lulz
  }
  g++;
}


If none of these scenarios fit, then you probably won't be able to use a loop, but you could use a custom function:

void SetButtonTextColor(int color)
{
  btnOne.TextColor = color;
  btnTwo.TextColor = color;
  // ...
  btnEighteen.TextColor = color;
}

// wherever..
SetButtonTextColor(15);
Title: Re: Bulk process a set of buttons?
Post by: hedgefield on Tue 07/06/2011 21:26:38
Awesome! Yes sorry I should have specified, all buttons are on the same GUI. And your first solution works like a charm :) Cheers!