Game Development Community

Class and NameSpaces

by Tony A · in Torque Game Builder · 07/22/2008 (5:49 pm) · 2 replies

Hi all,

ok here is the thing that's confusing me. I am trying to set the class field of a TCPObject so that all objects of this type would share some common functionality and callback funtions via the NameSpace. It just doesn't work. Here is what I did:

function newTcpConnection(%objName)
{
// name exists, do not create a new object with the same name.
if (isObject(%objName))
{
return %objName;
}
else
{
return (new TCPObject(%objName)
{
class = "TcpConnection";
isConnected = false;
lastMsgReceived = "";
lastMsgSent = "";
});
}
}

function TcpConnection::onConnected(%this)
{
%this.isConnected = true;
}


Do you guys see anything wrong with my setup?

Thanks!!

#1
07/23/2008 (4:15 am)
It's likely that the engine side code for TCPObject isn't linking in a class and superclass namespace.

If you have the source code, have a look at onAdd/onRemove and compare TCPObjects version to that of ScriptObject.
#2
07/23/2008 (5:27 pm)
Ok, I looked in TCPObject.cc and scriptObjects.cc and found that TCPObject does this in onAdd()

if(name && name[0] && getClassRep())
   {
      Namespace *parent = getClassRep()->getNameSpace();
      Con::linkNamespaces(parent->mName, name);
      mNameSpace = Con::lookupNamespace(name);

   }

while ScriptObject does this in the constructor:

mNSLinkMask = LinkSuperClassName | LinkClassName;

so it seems to me that TCPObject does not link in the class name to the namespace, it only sees the object name. I changed how the linking happens to match what ScriptObject does and now everything works!

If you guys see any side effects for my changes, please let me know.

thanks.