Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   'Dynamic' GUI Control Manipulation (https://forums.graalonline.com/forums/showthread.php?t=134257730)

Grey 01-21-2010 05:33 AM

'Dynamic' GUI Control Manipulation
 
I've just started playing with GUI Controls more recently and was wondering if anybody could tell me how to reference Gui Controls that are created dynamically.

for example

new GuiControl("Name"@var) {

}

And..something along the lines of:

("Name"@var).method();

cbk1994 01-21-2010 05:35 AM

That's exactly right :)

DustyPorViva 01-21-2010 05:39 AM

(@ "Name" @ var) edit: hmm, or maybe you don't need the initial concat!

However, you'd much rather use catchevent with such dynamically named objects, since otherewise you'd have to account for each var, and subsequent name.

PHP Code:

new GuiControl("Name" @ var) {
  
catchevent(this.name,"onMousedown","onGUIclicked");
}

function 
onGUIclicked(obj,keymod,mx,my,clicks) {
  
player.chat = obj.name @ " was clicked at " @ mx SPC my  @ ", " @ clicks @ " times!";
} 


Grey 01-21-2010 06:02 AM

D'oh, thanks both :D

I'd made a mistake with my looping so it wasn't calling correctly.

Quote:

Originally Posted by DustyPorViva (Post 1551530)
However, you'd much rather use catchevent with such dynamically named objects, since otherewise you'd have to account for each var, and subsequent name.

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.

DustyPorViva 01-21-2010 06:10 AM

Quote:

Originally Posted by Grey (Post 1551531)
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.


All times are GMT +2. The time now is 12:42 PM.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2026, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.