Get the parent
by Katrina Rose · in Torque Game Engine · 12/28/2004 (10:10 am) · 9 replies
I added a onAdd callback to the guiControl file so that I can capture the guiBitmapCtrl files as they are being added to the mission. I am storing them in an array as drop points for a multimeter simulator. My problem is that I need to know what guiControl they are comming from. Example:
IETMGui.gui or IETMEgiGui.gui
That way I can sort them out and put them in there proper array. I have tried %this.getGroup(), but it returns guiGroup. There is no getParent() method or anything that I can find. I thought about adding the parent into the:
but I don't know how to get it from c++ and I don't know where to put it in the line, or where to put it in:
Any help is apreciated,
Marrion
IETMGui.gui or IETMEgiGui.gui
That way I can sort them out and put them in there proper array. I have tried %this.getGroup(), but it returns guiGroup. There is no getParent() method or anything that I can find. I thought about adding the parent into the:
Con::executef(this, 2, "onAdd");
but I don't know how to get it from c++ and I don't know where to put it in the line, or where to put it in:
function GuiBitmapCtrl::onAdd( %this, %obj)
Any help is apreciated,
Marrion
About the author
#2
Is getClassName the same as parent? Where would I add that?
Marrion
12/28/2004 (10:28 am)
Thanks Westly,Is getClassName the same as parent? Where would I add that?
Marrion
#3
12/28/2004 (10:33 am)
Add that to the header file of the class you want it in. You will probably also have to add a console function to call it from script, but SimObject has it so you might not.
#4
This returns guiBitmapCtrl. This is my current heirchy:
1. NAME: IETMGui (gui)
2. NAME: IETMGuiWindow (guiWindowCtrl)
3. NAME: Drop1 *(guiBitmapCtrl)
I am at #3 and I need to know the name of Number 1 (IETMGui). I need the name of the gui that the current bitmap is on.
Thanks for your help,
Marrion
12/28/2004 (10:50 am)
@WestyThis returns guiBitmapCtrl. This is my current heirchy:
1. NAME: IETMGui (gui)
2. NAME: IETMGuiWindow (guiWindowCtrl)
3. NAME: Drop1 *(guiBitmapCtrl)
I am at #3 and I need to know the name of Number 1 (IETMGui). I need the name of the gui that the current bitmap is on.
Thanks for your help,
Marrion
#5
12/28/2004 (11:26 am)
Given GUIs are SimGroup derived, you should be able to use getGroup() or similar to figure out what group a given thing belongs to. Simply call it as many generations as you need, and you'll get the nth parent. Do a dump() on SimGroup (or on the gui control in question) to find the correct method name.
#6
I tried that first, but the problem is that I have to exec in the guiBitmapCtrl::onAdd method before the gui itself or it won't see any of the bitmaps. When I use the getGroup() method and then the getName() all I get is guiGroup. After that I get a -1 for the getName(). I think that's because of the order that I am loading the cs files, but I don't think I can change it without one or the other not working. Thanks for your help,
Marrion
12/28/2004 (11:33 am)
Thanks Ben,I tried that first, but the problem is that I have to exec in the guiBitmapCtrl::onAdd method before the gui itself or it won't see any of the bitmaps. When I use the getGroup() method and then the getName() all I get is guiGroup. After that I get a -1 for the getName(). I think that's because of the order that I am loading the cs files, but I don't think I can change it without one or the other not working. Thanks for your help,
Marrion
#7
12/28/2004 (1:05 pm)
I don't think it has anything to do with the order of the .cs files. Have you tried using tree() to see how things are set up?
#8
The echo returns nothing. I used the tree() view and the heirchy is as I described above:
guiCtrl (IETMgui)
guiWindowCtrl (IETMGuiWindow)
guiBitmapCtrl (Drop1)
If I echo(%this.getGroup().getName()) I get guiGroup. If I wait till the game is done loading everything and use:
echo($myThis.getGroup().getGroup().getName());
It returns IETMgui.
I don't understand why it won't work in the onAdd but works after.
Again thanks for your help. Any ideas?
Marrion
12/29/2004 (3:46 am)
This is how I have things set up:function GuiBitmapCtrl::onAdd( %this, %obj)
{
if (%this.bitmapType $= "Drop")
{
$myThis = %this;
%guiWindow = %this.getGroup();
%gui = %guiWindow.getGroup();
echo(strUpr(%gui.getName()));
switch$ (strUpr(%gui.getName()))
{
}
}
}The echo returns nothing. I used the tree() view and the heirchy is as I described above:
guiCtrl (IETMgui)
guiWindowCtrl (IETMGuiWindow)
guiBitmapCtrl (Drop1)
If I echo(%this.getGroup().getName()) I get guiGroup. If I wait till the game is done loading everything and use:
echo($myThis.getGroup().getGroup().getName());
It returns IETMgui.
I don't understand why it won't work in the onAdd but works after.
Again thanks for your help. Any ideas?
Marrion
#9
Also, you're aware that the code you have above, once parsed, will be executed for _all_ GuiBitmapCtrls?
12/29/2004 (11:02 pm)
Do you get any console errors?Also, you're aware that the code you have above, once parsed, will be executed for _all_ GuiBitmapCtrls?
Torque Owner Westy
static const char* getClassName() {return("this class name");}