Adventure Game Studio

AGS Support => Advanced Technical Forum => Topic started by: Shade on Thu 24/11/2011 23:55:07

Title: placeholder for button names [SOLVED]
Post by: Shade on Thu 24/11/2011 23:55:07
lets say i have a lot of buttons (all called Button + running number, eg Button1, Button2, ...) and i want to change their graphics individualy depending on the value of certain variables. now i don't want to call the buttons one by one.
here is what i mean. is there a way to simplify this:

int x;
int y;

while (x<100){

   y=Random(100);

    if (x==y){

if (x==0){

   Button0.NormalGraphic=y+1;
   Button0.Visible=true;

}
else if (x==1){

   Button1.NormalGraphic=y+1;
   Button1.Visible=true;

}
...
   }

   x++;

}


into something like this?:

int x;
int y;

while (x<100){

   y=Random(100);
   Buttonx=?

   if (x==y){

Buttonx.NormalGraphic=y+1;
Buttonx.Visible=true;

   }

   x++;

}


Buttonx should change into Button1, Button2, ... depending on the value of x. is there a way to achieve this somehow?

Thanks for your help!
Title: Re: placeholder for button names
Post by: monkey0506 on Fri 25/11/2011 01:07:59
Well, there's a few different ways you could go about doing this, depending on your implementation. If the buttons are sequentially ordered with no other controls in-between then you could just use GUI.Controls and GUIControl.AsButton.

You may also want to check out how pointers work.

You could do something like:

gMygui.Controls[index].AsButton.NormalGraphic = y + 1;

Where index is the ID of the button you want.
Title: Re: placeholder for button names
Post by: Shade on Fri 25/11/2011 01:45:00
exactly what i was looking for and so easy! thank you monkey_05_06!  :D