Datablocks and Namespaces...
by Cooper Sellers · in Torque Game Builder · 02/28/2006 (4:05 pm) · 6 replies
Okay, I have gone over the docs and looked at everything I could find and I am not understanding why this is not working as expected.
I have a datablock:
Now, I expect to be able to create functions such as :
and be able to use it such as this:
I won't even go into the wasted hours all due to that little 'config' in the t2dStaticSprite instanciation needing to be 'config' instead of 'datablock' like all the documentation I found states.
I have tried all manners of using quotes or not using quotes and nothing got me any closer to my target.
Is there something else the documentation is wrong about dealing with namespaces and classname, or am I doing something wrong?
I have a datablock:
datablock t2dStaticSpriteDatablock( thisDB )
{
maxLinearVelocity = 50;
minLinearVelocity = 20;
className = thisClassName;
};Now, I expect to be able to create functions such as :
function thisClassName::doIt( %this )
{
echo( %this SPC "doIt thisClassName" );
}and be able to use it such as this:
$test = new t2dStaticSprite( thisObj )
{
config = thisDB;
};
//
// Why doesn't this call the className namespace version?
// ie, why not thisClassName::doIt
//
$test.doIt();I won't even go into the wasted hours all due to that little 'config' in the t2dStaticSprite instanciation needing to be 'config' instead of 'datablock' like all the documentation I found states.
I have tried all manners of using quotes or not using quotes and nothing got me any closer to my target.
Is there something else the documentation is wrong about dealing with namespaces and classname, or am I doing something wrong?
About the author
#2
I will play with your work around and see if it will suit my purposes.
03/01/2006 (7:12 am)
Ah, thank you Stephen. I thought it might be something like that so instead of continuing to bang my head against my desk, I thought I would post up, glad I did =)I will play with your work around and see if it will suit my purposes.
#3
For your specific example, you will have 3 total namespaces available to you:
t2dStaticSprite:: (from the object's instantiation class)
thisObj:: (from the object's unique name)
thisDB:: (from the object's datablock)
Note that the third requires you to use the same syntax as I pointed out above. In this case, you would use the object's datablock namespace by:
$test.getDataBlock().doIt();
which would call:
thisDB::doIt(%this, ...)
{
}
With the "%this" variable being set to the ObjectID of the datablock.
03/01/2006 (7:20 am)
Just for completeness sake, the class/superclass (and your slightly incorrect use of classname) namespace links actually only work for ScriptObject instantiations, not "normal" instantiations.For your specific example, you will have 3 total namespaces available to you:
t2dStaticSprite:: (from the object's instantiation class)
thisObj:: (from the object's unique name)
thisDB:: (from the object's datablock)
Note that the third requires you to use the same syntax as I pointed out above. In this case, you would use the object's datablock namespace by:
$test.getDataBlock().doIt();
which would call:
thisDB::doIt(%this, ...)
{
}
With the "%this" variable being set to the ObjectID of the datablock.
#4
You mention that I should have an additional namespace such as :
thisObj:: (from the object's unique name)
I have tried that, but unable to get this to work.
I define the following 2 functions:
and call
which always returns t2dStaticSprite::doIt when I had hoped it would return thisObj::doIt.
Any pointers?
03/01/2006 (9:12 am)
Thanks for the additional info. One small problem though.You mention that I should have an additional namespace such as :
thisObj:: (from the object's unique name)
I have tried that, but unable to get this to work.
I define the following 2 functions:
function thisObj::doIt( %this )
{
echo( %this SPC "thisObj::doIt" );
}
function t2dStaticSprite::doIt( %this )
{
echo( %this SPC "t2dStaticSprite::doIt" );
}and call
$this.doIt()
which always returns t2dStaticSprite::doIt when I had hoped it would return thisObj::doIt.
Any pointers?
#5
"Just for completeness sake, the class/superclass (and your slightly incorrect use of classname) namespace links actually only work for ScriptObject instantiations, not "normal" instantiations."
That example will only work for ScriptObjects
You can do this
03/01/2006 (9:31 am)
Just reinforcing what Stephen said..."Just for completeness sake, the class/superclass (and your slightly incorrect use of classname) namespace links actually only work for ScriptObject instantiations, not "normal" instantiations."
That example will only work for ScriptObjects
You can do this
new ScriptObject(thisObj);
function thisObj::doIt( %this )
{
echo( %this SPC "thisObj::doIt" );
}
#6
I guess that it hasn't really clicked as to what all is applicable to any object vs only the ScriptObject.
Thanks Matt
03/01/2006 (9:48 am)
Ahhhhh, okay, yes, sorry, I see what you are saying.I guess that it hasn't really clicked as to what all is applicable to any object vs only the ScriptObject.
Thanks Matt
Torque 3D Owner Stephen Zepp
Not much of a workaround for you at the moment, but I've had success with using $test.config.doIt(); in cases like this. A better solution is being looked at!