placeholder for button names [SOLVED]

Started by Shade, Thu 24/11/2011 23:55:07

Previous topic - Next topic

Shade

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:

Code: ags
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?:

Code: ags
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!

monkey0506

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:

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


Where index is the ID of the button you want.

Shade

exactly what i was looking for and so easy! thank you monkey_05_06!  :D

SMF spam blocked by CleanTalk