Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: lafouine88 on Sun 27/12/2020 09:53:43

Title: button numbers shortcut
Post by: lafouine88 on Sun 27/12/2020 09:53:43
Hey Guys!
I ll try to make this simple...

I have 10 different buttons and I want to create a single function that could change their sprite NormalGraphic, with a variable.
My buttons are called button1,button2...button10

Is there a way to select those buttons with just one line of code, instead of detailing all the possibilities.

So instead of :
Code (ags) Select

{
var=Random(9);
if(var==1){button1.NormalGraphic++;}
else if(var==2){button2.NormalGraphic++;}
...
else if(var==9){button9.NormalGraphic++;}
else {button10.NormalGraphic++;}
}



I m looking for the correct spelling (if one) to do something like this :

Code (ags) Select

{
var=Random(9);
button[var].NormalGraphic++;
}



In other words, how to apply an int number to a button number ?
Do you see what I mean? And is that possible ? I guess so because it would be so heavy otherwise

Thanks a lot :)
Title: Re: button numbers shortcut
Post by: Khris on Mon 28/12/2020 12:48:25
You can use the GUI's  .Controls[]  array for that.
Title: Re: button numbers shortcut
Post by: lafouine88 on Mon 28/12/2020 13:35:56
That looks like a good lead,didn't know about this. Thanks a lot Khris! :)
Title: Re: button numbers shortcut(solved)
Post by: lafouine88 on Mon 28/12/2020 19:06:16
Ok so I tried and it's exactly what I needed, it saves a lot of time and is pretty easy to use.

Thanks again! ->solved