Creating A Package
Packages are used to package a group of functions. Utilizing packages is technically proper practice to incorporate into any script you write in Torquescript.
Initializing a package is simple, firstly you'll need to give that package a name. Let's do so below.
package myFirstPackage
{
function myFirstPackage()
{
//empty
}
};
So we now have a package ready, and the reason I put that empty function in there is because if you try to create a new package with nothing inside of it, you will be rewarded with a syntax error and the package will not be created.
Initializing a package is simple, firstly you'll need to give that package a name. Let's do so below.
package myFirstPackage
{
function myFirstPackage()
{
//empty
}
};
So we now have a package ready, and the reason I put that empty function in there is because if you try to create a new package with nothing inside of it, you will be rewarded with a syntax error and the package will not be created.
Default package functionality
There are 5 functions that you can use in conjunction with packages:
activatePackage(package);
This function will activate your given package. In layman's terms, it's going to act like a light switch and turn on your package.
deactivatePackage(package);
This function will do the opposite, and turn your package off.
isPackage(package);
This function will return true if the package is an existing package.
getNumActivePackages();
This function will return the number of active packages that currently exist.
getActivePackage(int_index);
This function will return an active package determined by the index (integer), you could use this with the above function.
There are 5 functions that you can use in conjunction with packages:
activatePackage(package);
This function will activate your given package. In layman's terms, it's going to act like a light switch and turn on your package.
deactivatePackage(package);
This function will do the opposite, and turn your package off.
isPackage(package);
This function will return true if the package is an existing package.
getNumActivePackages();
This function will return the number of active packages that currently exist.
getActivePackage(int_index);
This function will return an active package determined by the index (integer), you could use this with the above function.
So we want to activate myFirstPackage. Usually, you can just put the activatePackage(myFirstPackage) directly underneath the package declaration:
package myFirstPackage
{
function myFirstPackage()
{
//empty
}
};
activatePackage(myFirstPackage);
package myFirstPackage
{
function myFirstPackage()
{
//empty
}
};
activatePackage(myFirstPackage);