Graal Forums  

Go Back   Graal Forums > Development Forums > NPC Scripting
FAQ Members List Calendar Today's Posts

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 01-21-2010, 05:33 AM
Grey Grey is offline
Classic Developer
Grey's Avatar
Join Date: Mar 2007
Location: Wales, UK
Posts: 134
Grey will become famous soon enough
Send a message via AIM to Grey
'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();
Reply With Quote
  #2  
Old 01-21-2010, 05:35 AM
cbk1994 cbk1994 is offline
the fake one
cbk1994's Avatar
Join Date: Mar 2003
Location: San Francisco
Posts: 10,718
cbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond repute
Send a message via AIM to cbk1994
That's exactly right
__________________
Reply With Quote
  #3  
Old 01-21-2010, 05:39 AM
DustyPorViva DustyPorViva is offline
Will work for food. Maybe
DustyPorViva's Avatar
Join Date: Sep 2003
Location: Maryland, USA
Posts: 9,589
DustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond repute
Send a message via AIM to DustyPorViva Send a message via MSN to DustyPorViva
(@ "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!";

Reply With Quote
  #4  
Old 01-21-2010, 06:02 AM
Grey Grey is offline
Classic Developer
Grey's Avatar
Join Date: Mar 2007
Location: Wales, UK
Posts: 134
Grey will become famous soon enough
Send a message via AIM to Grey
D'oh, thanks both

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

Quote:
Originally Posted by DustyPorViva View Post
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.
Reply With Quote
  #5  
Old 01-21-2010, 06:10 AM
DustyPorViva DustyPorViva is offline
Will work for food. Maybe
DustyPorViva's Avatar
Join Date: Sep 2003
Location: Maryland, USA
Posts: 9,589
DustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond repute
Send a message via AIM to DustyPorViva Send a message via MSN to DustyPorViva
Quote:
Originally Posted by Grey View Post
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.
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 01:10 PM.


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