Quote:
Originally Posted by Grey
I think running through all of the controls is the only way given what I'm doing. New Gui Controls are generated for each item in a list, and when a new list is referenced the old Controls are being removed from the GUI.
Though I'm also thinking now it'd be faster / better to just replace Controls where applicable rather than destroying / recreating.
|
This is exactly what catchevent is for. Just place the catchevent in the dynamic GUI controls and it will call the function for all of them, and thus you can control them with one single function.
For example:
PHP Code:
function onCreated() {
for (temp.i=0;i<10;i++) {
new GuiControl("Name" @ i) {
catchevent(this.name,"onMousedown","onGUIclicked");
}
}
}
function onGUIclicked(obj,keymod,mx,my,clicks) {
player.chat = obj.name @ " was clicked at " @ mx SPC my @ ", " @ clicks @ " times!";
}
Will set the player's chat to 'Name0', 'Name1' and so on and so forth, for each dynamic GUI you click on. You don't have to worry about handling all the variables and such. You just have one function for it all. In fact, the name of the GUI becomes irrelevant at this point.