Any Trick to using TorqueScript packages?
by Chris Groot · in Torque 3D Professional · 04/26/2011 (2:02 pm) · 2 replies
I'm trying to use packages to swap between two different implementations for the same function but I am having an issue swapping between packages and wondering if anyone might be able to help me. I have defined the function the same for both packages, check to make sure both packages are valid packages before attempting to activate/deactivate them, and deactivate the first package before activating the second package. The result I get is that the first activated package definition gets used every time regardless of which package is activated. Wondering what I have done that may have caused that?
Package declarations:
If I start by changing to MainMenuPackage the output will be recursive:
"Mainmenu suit"
Any ideas as to what is causing this oddness?
Package declarations:
package MainMenuPackage
{
function InitializeSUITPage()
{
echo("Mainmenu suit");
ChangePackage(MainMenuPackage2);
}
};
package MainMenuPackage2
{
function InitializeSUITPage()
{
echo("Mainmenu2 suit");
}
};Helper Function definition:function ChangePackage(%PackageToChangeTo)
{
if(!isPackage(%PackageToChangeTo))
return;
%OldPackage = $CurrentPackage;
if(%OldPackage !$= "")
deactivatePackage(%OldPackage);
activatePackage(%PackageToChangeTo);
$CurrentPackage = %PackageToChangeTo;
InitializeSUITPage();
}If I start by changing to MainMenuPackage the output will be recursive:
"Mainmenu suit"
Any ideas as to what is causing this oddness?
Associate Manoel Neto
Default Studio Name
Try this:
function ChangePackage(%PackageToChangeTo) { if(!isPackage(%PackageToChangeTo)) return; %OldPackage = $CurrentPackage; if(%OldPackage !$= "") deactivatePackage(%OldPackage); activatePackage(%PackageToChangeTo); $CurrentPackage = %PackageToChangeTo; schedule(0,0, InitializeSUITPage); //schedules the execution, instead of recursing }