Game Development Community

script functions(?)

by Jonathan Flom · in Torque Game Engine · 04/12/2002 (12:07 pm) · 3 replies

Hi there,
this is about making up packages/functions...

I've created a button wich does,
Server::MissionType="specialmission"
and createServer(mymission,type)

I made a package Special.cs
package Special {
function TP_Greet() {echo("...")}
}
activatepackage(Special)

in client init.cs I exec("./scripts/special.cs");

then the load at torque\example\common\server\missionLoad.cs
function loadMission( %missionName, %isFirstMission )
I added
if($Server::MissionType == "Training")
Special::Greet();

shouldnt be working? I get no echos

#1
04/12/2002 (12:19 pm)
are you exec-ing missionLoad.cs?
#2
04/12/2002 (12:46 pm)
I dont really understand what you are saying but I'll help explain packages to you.

package myPackage 
{
   function onMissionDownloadComplete()
   {
      echo("---Mission Download Complete---");
      Parent::onMissionDownloadComplete();
   }
};
activatepackage(myPackage);
If you place this in myPackage.cs and exec it in client/init.cs the package will basically override onMissionDownloadComplete within missionDownload.cs .

The call to Parent::onMissionDownloadComplete() calls the actual function itself within missionDownload.cs . I could choose to override the function completely by not including this line. I could also choose to perform the parent operations first before performing my own functions -- dependant on when you call Parent::

It is extremely important to know the scope that the functions are in. What I mean by that is a client script can not overload a server function. So if you need to override server functions you need to exec your package via server not via client, and if you want to override client functions you want to exec your package via client and not via server.

What it looks like you were trying to do was package (override) a server function via client side, which will not work.
#3
04/12/2002 (4:03 pm)
ok let's put it that way...

say u want to make a package and different functions...
like my Special::Greet();

can u call them from anywhere without no problem like
in missionLoad.cs I could add Special::Greet() and it will execute the function?

how can u make it, and call it from anywhere, not to replace and other function, just make my own ones.

tx