Game Development Community

Mission TorqueScript file

by ROGER E PEDERSEN · in Torque Developer Network · 08/27/2009 (8:25 pm) · 1 replies

I want to use a variable such as PlayMode to determine which assets get launchedd
in the Mission TorqueScript file.

if( PlayMode == 1 ){
new TSStatic() {
canSaveDynamicFields = "1";
Enabled = "1";
position = "3.7 -17.1988 51.2088";
rotation = "0 0 1 1.14602";
scale = "1 1 1";
shapeName = "scriptsAndAssets/data/shapes/Box/box1.dts";
receiveSunLight = "1";
receiveLMLighting = "1";
useCustomAmbientLighting = "0";
customAmbientLighting = "0 0 0 1";
usePolysoup = "0";
allowPlayerStep = "1";
};
}
if( PlayMode == 2){
new TSStatic() {
canSaveDynamicFields = "1";
Enabled = "1";
position = "3.1 -17.1988 51.2088";
rotation = "1 0 0 0";
scale = "1 1 1";
shapeName = "scriptsAndAssets/data/shapes/Box/box2.dts";
receiveSunLight = "1";
receiveLMLighting = "1";
useCustomAmbientLighting = "0";
customAmbientLighting = "0 0 0 1";
usePolysoup = "0";
allowPlayerStep = "1";
};
}

What do I need to write to achieve this?

Roger

#1
08/28/2009 (9:43 am)
Roger Its the same as for loading and saving games. You would need to just use the FileIO system to create your modified Datablocks.

Perhaps an example would make this easier to understand. This is entirely from my point of view and should not be considered as the only way.

First, I want you to understand that any script you write has to go through an interpretor. We will call this interpretor "Console".

Console is a machine and is very dumb. If it thinks it will not understand what you type it will just hang. The rest of the document you are trying to process will just be skipped and in console it will tell you there was a script error in red.

I would then create a default mission file with the lines that I want to test for.
new TSStatic() {
canSaveDynamicFields = "1";
Enabled = "1";
position = "3.7 -17.1988 51.2088";
rotation = "0 0 1 1.14602";
scale = "1 1 1";
shapeName = **THISLINE**;  //This being the identifier from your default mission
receiveSunLight = "1";
receiveLMLighting = "1";
useCustomAmbientLighting = "0";
customAmbientLighting = "0 0 0 1";
usePolysoup = "0";
allowPlayerStep = "1";
};

I would then make a function like checkMission that would parse the mission file for the special lines "**THISLINE**" and replace it with whatever it is I want it to load. After I created the new mission file I would load that.

A link to the documentation on how to use File Objects.
tdn.garagegames.com/wiki/TorqueScript_FileObject

function exampleMissionModification(%mission, %checkLine, %replacement)
{
   //Example Variables you would normally pass the function
   %mission = Mission1;
   %checkLine = "shapeName = **THISLINE**;";
   %replacement = "shapeName = scriptsAndAssets/data/shapes/Box/box2.dts;";
   if(!%mission || !%checkLine || !%replacement)
      return;

   %file = new FileObject();
   %newFile = new FileObject();
   %file.OpenForRead("./", %mission, ".mis");
   %newFile.OpenForWrite("./realMission.mis");
   while( !%file.isEOF() )
   {
       %line = %file.readline();
       if( %line $= "shapeName = **THISLINE**;" )
          %newFile.writeLine( %replacement );
       else
          %newFile.writeLine( %line );
   }
   
   %newFile.close();
   %file.close();
}
I hope that helps!