Name Spacing
You can create objects in Torquescript that have their own functions. They are object oriented functions, they use namespacing.
First we need to create an object, for this example we will be using a script object (SO).
new scriptObject(myObject);
//%this is referencing myObject
function myObject::kill(%this)
{
echo("Killing "@%this.getName());
}
myObject.kill();
OUPUT:
==> "Killing myObject"
new scriptObject(myObject);
//%this is referencing myObject
function myObject::kill(%this)
{
echo("Killing "@%this.getName());
}
myObject.kill();
OUPUT:
==> "Killing myObject"
We can also use classes instead, for example:
new scriptObject(myObject)
{
class = myObjectClass;
};
function myObject::echoClass(%this)
{
%this.class.echo();
}
function myObjectClass::echo(%this)
{
echo("Class = "@%this);
}
So if we do:
myObject.echoClass();
it'll echo the object's class, classes can run functions as you can see.
new scriptObject(myObject)
{
class = myObjectClass;
};
function myObject::echoClass(%this)
{
%this.class.echo();
}
function myObjectClass::echo(%this)
{
echo("Class = "@%this);
}
So if we do:
myObject.echoClass();
it'll echo the object's class, classes can run functions as you can see.