button numbers shortcut

Started by lafouine88, Sun 27/12/2020 09:53:43

Previous topic - Next topic

lafouine88

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

{
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

{
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 :)

Khris

You can use the GUI's  .Controls[]  array for that.

lafouine88

That looks like a good lead,didn't know about this. Thanks a lot Khris! :)

lafouine88

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

SMF spam blocked by CleanTalk