Referring to children GUI elements
by Eero Karvonen · in Torque 2D Beginner · 06/01/2014 (12:39 pm) · 3 replies
I noticed that an efficient way to build a T2D GUI is to use the GUI editor in the commercial Torque Game Builder. It writes out a hierarchical bracket definition as follows,
When I need to access single GUI elements directly, I would intuitively do this:
The only way I seem to get it working is by using Internal Names instead of just names,
Can anyone point out if there's a more elegant and shorter way to address subwidgets? What is the sole "name" attribute good for if you can only address objects by their "internal name"?
%guiContent = new GuiWindowCtrl(SubWindow) {
new GuiTextCtrl(Widget1) {
//
};
new GuiTextCtrl(Widget2) {
//
};
};So, no TAML but a creation code snippet.When I need to access single GUI elements directly, I would intuitively do this:
// First attach the gui to our master window
exec("myGuiFile.gui");
$MasterWindow.addGuiControl( %guiContent );
// Now set the text for widget 1
$MasterWindow.SubWindow.Widget1.setValue("something");But unfortunately it doesn't work this way.The only way I seem to get it working is by using Internal Names instead of just names,
%guiContent = new GuiWindowCtrl() {
internalName = "SubWindow";
new GuiTextCtrl() {
internalName = "Widget1";
};
new GuiTextCtrl() {
internalName = "Widget2";
};
};And then this extremely long line yields the wanted result,$MasterWindow.findObjectByInternalName("SubWindow").findObjectByInternalName("Widget").setValue("something");Can anyone point out if there's a more elegant and shorter way to address subwidgets? What is the sole "name" attribute good for if you can only address objects by their "internal name"?
#2
Here is another great thing that has been left out of the syntax documentation,
06/02/2014 (12:07 pm)
Wow! I had no idea that this operator was even available. Thanks, Richard!Here is another great thing that has been left out of the syntax documentation,
%firstWord = %string._0; %secondWord = %string._1; ...
#3
06/02/2014 (7:09 pm)
Ah, yeah, but I think that specific syntax is relatively new. Although,%myArray[0]; %myArray_0; // I think there's an underscore there....has been around forever - and I can't remember the separator.
Torque Owner Richard Ranft
Roostertail Games
// using internal names for "indirection" - use the internal names like so: $MasterWindow->SubWindow->Widget.setValue("something"); // you were on the right track with $MasterWindow.SubWindow.Widget1.setValue("something");Should work if you've named everything using the internalName field. It does work if you're in T3D and I believe this functionality was there in TGE, so theoretically T2D shares it.