Game Development Community

Packages, Namespaces and special keywords

by John Smith_FX · in Torque Game Engine · 07/15/2008 (8:07 am) · 2 replies

Hello!

When you define a function in package, you can call the overriden function with "Parent::myFunction();" synthax.

I've tried to call the overriden function outiside the package, but it just doesn't work. It looks like that "Parent::" is an unexisting namespace and that the sythax above is just special keyword reserved only for packages
-Now please tell me what else can respresent the "::" since it's not reserved only for namespaces.

#1
08/09/2008 (5:34 am)
Packages need to be activated/deactivated.
Look out for their visibility, use the package after its declaration.

function play(%val) {}

package MyPackage { function play(%val) { ...... } };

ActivatePackage(MyPackage); // now use the package play
DeactivatePackage(MyPackage) // now use the first play, stop polymorphism

Also 'parent' is used within a package (or console method) only.
#2
08/09/2008 (12:31 pm)
You can also use :: to directly call any function/method that has a namespace, the only different between using :: and . is that %this will not get passed in.

Eg...

function Bla::method1( %this )
{
   echo( "Bla::method1" );
}

new ScriptObject(Bla);

Bla.method1();

// is the same as...

Bla::method1(Bla);

You can also use Parent, if you declare multiple methods with the same name but at different levels of namespace-linkage for an object, to call up the heirarchy ( eg. calling the overriden method ).

function BlaSuperClass::method1( %this )
{
   echo( "BlaSuperClass::method1");
}

function BlaClass::method1( %this )
{
   echo( "BlaClass::method1");

   // Calls BlaSuperClass::method1
   Parent::method1( %this );
}

function BlaName::method1( %this )
{
   echo( "BlaName::method1" );

   // Calls BlaClass::method1
   Parent::method1( %this );
}

%obj = new ScriptObject(BlaName)
{
   SuperClass = BlaSuperClass;
   Class = BlaClass;
};

// Calls BlaName::method1
%bla.method1();