Game Development Community

InternalName overview ?

by Orion Elenzil · in Torque Game Engine · 05/01/2007 (10:06 am) · 2 replies

Hey all - can someone give me a brief overview of what the "internalName" field of SimBase ?

i see this in the code but i'm still a bit blank:
//-----------------------------------------------------------------------------
//	Set the internal name, can be used to find child objects
//	in a meaningful way, usually from script, while keeping
//	common script functionality together using the controls "Name" field.
//-----------------------------------------------------------------------------

tia,
ooo

#1
05/01/2007 (2:27 pm)
Copy/paste from TDN article: TGB/Reference:_SimGroup (not sure why it ended-up in TGB, as this is a "Base" for all Torque engines..), in case you don't have TGB.

.findObjectByInternalName( string InternalName ) -> handle
Returns the handle to the object in the SimGroup with the given internal name (set by SimObject::setInternalName()).

Usage

First, we create some objects that we will add to the SimGroup:

==>$f0 = new SimObject() { internalName = "Apple"     ; } ; 
==>$f1 = new SimObject() { internalName = "Pear"      ; } ; 
==>$f2 = new SimObject() { internalName = "Orange"    ; } ; 
==>$f3 = new SimObject() { internalName = "Fig"       ; } ; 
==>$f4 = new SimObject() { internalName = "Persimmon" ; } ;
With that preliminary done, we can now create the SimGroup and add the objects.
==>$g=new SimGroup(FruitGroup);
==>$g.add($f0);$g.add($f1);$g.add($f2);$g.add($f3);$g.add($f4);
The only method this class introduces is exercised here. Note that the return value of findObjectByInternalName() is the handle to the object. We can recover the internal name from the handle to convince ourselves that the function executed as we expected.

==>echo($g.findObjectByInternalName(Apple));
2883
==>echo($g.findObjectByInternalName(Apple).getName());
Apple
Here is a different way to utilize the new method.
==>$g.listObjects();
   2883,"Apple": SimObject 
   2884,"Pear": SimObject 
   2885,"Orange": SimObject 
   2886,"Fig": SimObject 
   2887,"Persimmon": SimObject 
==>$g.pushToBack($g.findObjectByInternalName(Apple));
==>$g.listObjects();
   2884,"Pear": SimObject 
   2885,"Orange": SimObject 
   2886,"Fig": SimObject 
   2887,"Persimmon": SimObject 
   2883,"Apple": SimObject

Quite good explanation. I found it useful while working with some complicated GUI's.
#2
05/01/2007 (4:50 pm)
Hey Bank, thanks.

ooooh,
the key is that findObjectByInternalName() only searches children of the SimGroup.

.. as opposed to the normal object name which is global.

thanks.