Game Development Community

Creating a path

by CodingChris · in Torque Game Engine · 10/04/2007 (10:59 am) · 25 replies

Hi,
I just want to create a path from script in starter.racing. My plan is to get the position of the current checkpoint, of all items inside this checkpoint and of the next checkpoint. Then I want to create a path from this values. This is my code:
//-----------------------------------------------------------------------------
// Torque Game Engine
// Copyright (C) GarageGames.com, Inc.
//-----------------------------------------------------------------------------

datablock TriggerData(CheckPointTrigger)
{
   // The period is value is used to control how often the console
   // onTriggerTick callback is called while there are any objects
   // in the trigger.  The default value is 100 MS.
   tickPeriodMS = 100;
};

//-----------------------------------------------------------------------------

function CheckPointTrigger::onEnterTrigger(%this,%trigger,%obj)
{
	Parent::onEnterTrigger(%this,%trigger,%obj);

	if(%obj.client.nextCheck == %trigger.checkpoint)
	{
	centerPrint(%obj.client, "Checkpoint!", 1, 1);
	//Bot
	 if(%obj.isAIControlled()) {
 %count2 = 1;
 new Path (%trigger.nextCheck+"Path") {
	new Marker("mycheck") {
	position = %trigger.getTransform();
		   rotation = "1 0 0 0";
           scale = "1 1 1";
		   seqnum = %count2
	};
	%groupName = %trigger.nextCheck;
   %group = nameToID(%groupName);

   if (%group != -1) {
      %count = %group.getCount();
      if (%count != 0) {
         while (%count != 0)
		 {
         %spawn = %group.getObject(%index);
        new Marker (%spawn + "1")
		{
		position = %spawn.getTransform();
		   rotation = "1 0 0 0";
           scale = "1 1 1";
		   seqnum = %count2
		};
		 %count = %count - 1;
		 %count2 = %count2 + 1;
		 }
      }
      else
         error("No spawn points found in " @ %groupName);
   }
   else
      error("Missing spawn points group " @ %groupName);
new Marker("mycheck2") {
	position = %trigger.nextCheck.getTransform();
		   rotation = "1 0 0 0";
           scale = "1 1 1";
		   seqnum = %count2
	};
	  };
}  
  //Bot
	$pos = getWords( ServerConnection.getControlObject().getTransform(),0,2);
		if(%trigger.isLast)
		{
			// Player has completed a lap.
			%obj.client.lap++;
centerPrint(%obj.client, "Lap complete!", 1, 1);
			if(%obj.client.lap >= $Game::Laps)
			{
			centerPrint(%obj.client, "Complete!", 1, 1);
				// Increase his score by 1.
				%obj.client.incScore(1);
            	// End the game
             	cycleGame();			
			}
			else {
				%obj.client.nextCheck = 1;
				commandToClient(%obj.client, 'IncreaseLapCounter');
			}
		}
		else {
			// Continue to the next one.
			clientCmdCheck();
			%obj.client.nextCheck++;
		}
	}
	else
		centerPrint(%obj.client, "Wrong Checkpoint!", 1, 1);
}
What's wrong here?
Page «Previous 1 2
#1
10/04/2007 (11:10 am)
How about telling us what's wrong? I.e. what does the above code do when you try and run it? Where's it going wrong?

I answered a question about creating paths in script the other day, here's some recycled information:
function addPath()
{
   // Create our path object
   %path = new Path(Human1Path) {
      canSaveDynamicFields = "1";
      isLooping = "1";

      // Add some markers to our newly created path object
      new Marker(Marker1) {
         canSaveDynamicFields = "1";
         internalName = "wait5";
         position = "792.084 832.16 -28.8";
         rotation = "1 0 0 0";
         scale = "1 1 1";
         seqNum = "1";
         type = "Normal";
         msToNext = "1000";
         smoothingType = "Spline";
      };
      new Marker(Marker2) {
         canSaveDynamicFields = "1";
         position = "699.117 795.757 -29.0381";
         rotation = "1 0 0 0";
         scale = "1 1 1";
         seqNum = "2";
         type = "Normal";
         msToNext = "1000";
         smoothingType = "Spline";
      };
   };

   // Add the path to the mission group
   MissionCleanup.add(%path);

   // Create a new SimGroup that will hold our path
   new SimGroup (Paths) {};
   // Add the path we created above to the SimGroup
   Paths.add(%path);
   
   // Use Marker1.getTransform() & Marker1.setTransform()
   // to obtain and set the position of said marker respectively.
   
   // Type Marker1.dump into console to view all available methods
   // Type Paths.dump into console to view all available methods
}
#2
10/04/2007 (11:16 am)
This is my log:
Game/server/scripts/checkpoint.cs Line: 32 - parse error
>>> Advanced script error report. Line 32.
>>> Some error context, with ## on sides of error halt:
^centerPrint(%obj.client, "Checkpoint!", 1, 1);

^//Bot

^ if(%obj.isAIControlled()) {

%count2 = 1;

new Path (%trigger.nextCheck+"Path") {

^new Marker("mycheck") {

^position = %trigger.getTransform();

^^ rotation = "1 0 0 0";

scale = "1 1 1";

^^ seqnumber = %count2

^};

##^##%groupName = %trigger.nextCheck;

%group = nameToID(%groupName);



if (%group != -1) {

%count = %group.getCount();

if (%count != 0) {

while (%count != 0)

^^ {

%spawn = %group.getObject(%index);

new Marker (%spawn + "1")
>>> Error report complete.
#3
10/04/2007 (11:37 am)
Well I'm drunk at the moment but none of your brackets line up! There's too many errors in your script for me to comprehend and your formatting is all over the place!
#4
10/04/2007 (11:53 am)
Now I hope my fortmatting is better:
//Bot
	// Check AI
	 if(%obj.isAIControlled()) {

 new Path (%trigger.nextCheck+"Path") {
	//create path
	new Marker("mycheck") {
	position = %trigger.getTransform();
		   rotation = "1 0 0 0";
           scale = "1 1 1";
		   seqnum = %count2
	};
	 %count2 = 1;
	 //created first marker = current checkpoint
	 //set group name 
	%groupName = %trigger.nextCheck;
   %group = nameToID(%groupName);
//check if it is valid

   if (%group != -1) {
   //get items
      %count = %group.getCount();
      if (%count != 0) {
	  
         while (%count != 0)
		 {
		 //get selected object
         %spawn = %group.getObject(%index);
        //create next marker = next object inside of current checkpoint
		new Marker (%spawn + "1")
		{
		   position = %spawn.getTransform();
		   rotation = "1 0 0 0";
           scale = "1 1 1";
		   seqnum = %count2
		};
		//created marker
		//numbers
		 %count = %count - 1;
		 %count2 = %count2 + 1;
		 }
		 // do it again
      }
      else
         error("No items in " @ %groupName);
   }
   else
   // checkpoint is not valid
      error("Missing spawn points group " @ %groupName);
//create last marker = next checkpoint
	  new Marker("mycheck2") {
	       position = %trigger.nextCheck.getTransform();
		   rotation = "1 0 0 0";
           scale = "1 1 1";
		   seqnum = %count2
	};
	//close marker
	  };
	  //close Path
}  
//close if

  //Bot
^
Now I've got:
Game/server/scripts/checkpoint.cs Line: 34 - parse error
>>> Advanced script error report.  Line 34.
>>> Some error context, with ## on sides of error halt:
^//Bot

^// Check AI

^ if(%obj.isAIControlled()) {



 new Path (%trigger.nextCheck+"Path") {

^//create path

^new Marker("mycheck") {

^position = %trigger.getTransform();

^^   rotation = "1 0 0 0";

           scale = "1 1 1";

^^   seqnum = %count2

^};

##^## %count2 = 1;

^ //created first marker = current checkpoint

^ //set group name 

^%groupName = %trigger.nextCheck;

   %group = nameToID(%groupName);

//check if it is valid



   if (%group != -1) {

   //get items

      %count = %group.getCount();

      if (%count != 0) {
>>> Error report complete.
#5
10/05/2007 (1:45 am)
Now I made this and fixed the most errors:
//-----------------------------------------------------------------------------
// Torque Game Engine
// Copyright (C) GarageGames.com, Inc.
//-----------------------------------------------------------------------------

datablock TriggerData(CheckPointTrigger)
{
   // The period is value is used to control how often the console
   // onTriggerTick callback is called while there are any objects
   // in the trigger.  The default value is 100 MS.
   tickPeriodMS = 100;
};

//-----------------------------------------------------------------------------

function CheckPointTrigger::onEnterTrigger(%this,%trigger,%obj)
{
	Parent::onEnterTrigger(%this,%trigger,%obj);

	if(%obj.client.nextCheck == %trigger.checkpoint)
	{
	centerPrint(%obj.client, "Checkpoint!", 1, 1);
	//Bot
	// Check AI
	 if(%obj.isAIControlled()) {

 %path = new Path (%trigger.nextCheck+"Path") {
	//create path
	new Marker("mycheck") {
	       canSaveDynamicFields = "1";
		   position = %trigger.getTransform();
		   rotation = "1 0 0 0";
           scale = "1 1 1";
		   seqnum = %count2;
		   type = "Normal";
           msToNext = "1000";
           smoothingType = "Linear";
		   speed = "60";
	};
	 %count2 = 1;
	 //created first marker = current checkpoint
	 //set group name 
	%groupName = %trigger.nextCheck;
   %group = nameToID(%groupName);
//check if it is valid

   if (%group != -1) {
   //get items
      %count = %group.getCount();
      if (%count != 0) {
	  
         while (%count != 0)
		 {
		 //get selected object
         %spawn = %group.getObject(%index);
        //create next marker = next object inside of current checkpoint
		new Marker (%spawn + "1")
		{
		   canSaveDynamicFields = "1";
		   position = %spawn.getTransform();
		   rotation = "1 0 0 0";
           scale = "1 1 1";
		   seqnum = %count2;
		   type = "Normal";
           msToNext = "1000";
           smoothingType = "Linear";
		   
		};
		//created marker
		//numbers
		 %count = %count - 1;
		 %count2 = %count2 + 1;
		 }
		 // do it again
      }
      else
         error("No items in " @ %groupName);
   }
   else
   // checkpoint is not valid
      error("Missing spawn points group " @ %groupName);
//create last marker = next checkpoint
	  new Marker("mycheck2") {
	       canSaveDynamicFields = "1";
		   position = %trigger.nextCheck.getTransform();
		   rotation = "1 0 0 0";
           scale = "1 1 1";
		   seqnum = %count2;
		   type = "Normal";
           msToNext = "1000";
           smoothingType = "Linear";
	};
	//close marker
	  };
	  //close Path
	  MissionCleanup.add(%path);
}  
//close if

  //Bot
	$pos = getWords( ServerConnection.getControlObject().getTransform(),0,2);
		if(%trigger.isLast)
		{
			// Player has completed a lap.
			%obj.client.lap++;
centerPrint(%obj.client, "Lap complete!", 1, 1);
			if(%obj.client.lap >= $Game::Laps)
			{
			centerPrint(%obj.client, "Complete!", 1, 1);
				// Increase his score by 1.
				%obj.client.incScore(1);
            	// End the game
             	cycleGame();			
			}
			else {
				%obj.client.nextCheck = 1;
				commandToClient(%obj.client, 'IncreaseLapCounter');
			}
		}
		else {
			// Continue to the next one.
			clientCmdCheck();
			%obj.client.nextCheck++;
		}
	}
	else
		centerPrint(%obj.client, "Wrong Checkpoint!", 1, 1);
}
and got this log:
Compiling Game/server/scripts/checkpoint.cs...
Game/server/scripts/checkpoint.cs Line: 40 - parse error
>>> Advanced script error report.  Line 40.
>>> Some error context, with ## on sides of error halt:
^^   position = %trigger.getTransform();

^^   rotation = "1 0 0 0";

           scale = "1 1 1";

^^   seqnum = %count2;

^^   type = "Normal";

           msToNext = "1000";

           smoothingType = "Linear";

^^   speed = "60";

^};

^ %count2 = 1;

##^## //created first marker = current checkpoint

^ //set group name 

^%groupName = %trigger.nextCheck;

   %group = nameToID(%groupName);

//check if it is valid



   if (%group != -1) {

   //get items

      %count = %group.getCount();

      if (%count != 0) {
>>> Error report complete.
#6
10/05/2007 (2:25 am)
Now I made this:
//-----------------------------------------------------------------------------
// Torque Game Engine
// Copyright (C) GarageGames.com, Inc.
//-----------------------------------------------------------------------------

datablock TriggerData(CheckPointTrigger)
{
   // The period is value is used to control how often the console
   // onTriggerTick callback is called while there are any objects
   // in the trigger.  The default value is 100 MS.
   tickPeriodMS = 100;
};

//-----------------------------------------------------------------------------

function CheckPointTrigger::onEnterTrigger(%this,%trigger,%obj)
{
	Parent::onEnterTrigger(%this,%trigger,%obj);

	if(%obj.client.nextCheck == %trigger.checkpoint)
	{
	centerPrint(%obj.client, "Checkpoint!", 1, 1);
	//Bot
	// Check AI
	 if(%obj.isAIControlled()) {
$count2 = 1;
 %path = new Path (%trigger.nextCheck+"Path") {
	//create path
	new Marker("mycheck") {
	       canSaveDynamicFields = "1";
		   position = %trigger.getTransform();
		   rotation = "1 0 0 0";
           scale = "1 1 1";
		   seqnum = $count2;
		   type = "Normal";
           msToNext = "1000";
           smoothingType = "Linear";
		   speed = "60";
	};
	 
	 //created first marker = current checkpoint
	 //set group name 
	$groupName = %trigger.nextCheck;
   $group = nameToID(%groupName);
//check if it is valid

   if ($group != -1) {
   //get items
      %count = $group.getCount();
      if (%count != 0) {
	  
         while (%count != 0)
		 {
		 //get selected object
         %spawn = $group.getObject(%index);
        //create next marker = next object inside of current checkpoint
		new Marker (%spawn + "1")
		{
		   canSaveDynamicFields = "1";
		   position = %spawn.getTransform();
		   rotation = "1 0 0 0";
           scale = "1 1 1";
		   seqnum = $count2;
		   type = "Normal";
           msToNext = "1000";
           smoothingType = "Linear";
		   
		};
		//created marker
		//numbers
		 %count = %count - 1;
		 $count2 = $count2 + 1;
		 }
		 // do it again
      }
      else
         error("No items in " @ %groupName);
   }
   else
   // checkpoint is not valid
      error("Missing spawn points group " @ %groupName);
//create last marker = next checkpoint
	  new Marker("mycheck2") {
	       canSaveDynamicFields = "1";
		   position = %trigger.nextCheck.getTransform();
		   rotation = "1 0 0 0";
           scale = "1 1 1";
		   seqnum = $count2;
		   type = "Normal";
           msToNext = "1000";
           smoothingType = "Linear";
	};
	//close marker
	  };
	  //close Path
	  MissionCleanup.add(%path);
}  
//close if

  //Bot
	$pos = getWords( ServerConnection.getControlObject().getTransform(),0,2);
		if(%trigger.isLast)
		{
			// Player has completed a lap.
			%obj.client.lap++;
centerPrint(%obj.client, "Lap complete!", 1, 1);
			if(%obj.client.lap >= $Game::Laps)
			{
			centerPrint(%obj.client, "Complete!", 1, 1);
				// Increase his score by 1.
				%obj.client.incScore(1);
            	// End the game
             	cycleGame();			
			}
			else {
				%obj.client.nextCheck = 1;
				commandToClient(%obj.client, 'IncreaseLapCounter');
			}
		}
		else {
			// Continue to the next one.
			clientCmdCheck();
			%obj.client.nextCheck++;
		}
	}
	else
		centerPrint(%obj.client, "Wrong Checkpoint!", 1, 1);
}
and have this in my log:
Compiling Game/server/scripts/checkpoint.cs...
Game/server/scripts/checkpoint.cs Line: 43 - parse error
>>> Advanced script error report.  Line 43.
>>> Some error context, with ## on sides of error halt:
           scale = "1 1 1";

^^   seqnum = $count2;

^^   type = "Normal";

           msToNext = "1000";

           smoothingType = "Linear";

^^   speed = "60";

^};

^ 

^ //created first marker = current checkpoint

^ //set group name 

^$groupName = %trigger.nextCheck;

## ##  $group = nameToID(%groupName);

//check if it is valid



   if ($group != -1) {

   //get items

      %count = $group.getCount();

      if (%count != 0) {

^  

         while (%count != 0)

^^ {

^^ //get selected object

         %spawn = $group.getObject(%index);
>>> Error report complete.
sorry, but I really cannot find my errors. Please help me.
#7
10/05/2007 (2:58 am)
First things first, let's clean up the formatting. This will make it easier for other people to read.

//-----------------------------------------------------------------------------
// Torque Game Engine
// Copyright (C) GarageGames.com, Inc.
//-----------------------------------------------------------------------------

datablock TriggerData(CheckPointTrigger)
{
   // The period is value is used to control how often the console
   // onTriggerTick callback is called while there are any objects
   // in the trigger.  The default value is 100 MS.
   tickPeriodMS = 100;
};

//-----------------------------------------------------------------------------

function CheckPointTrigger::onEnterTrigger(%this,%trigger,%obj)
{
   Parent::onEnterTrigger(%this,%trigger,%obj);

   if(%obj.client.nextCheck == %trigger.checkpoint)
   {
      centerPrint(%obj.client, "Checkpoint!", 1, 1);
      //Bot
      // Check AI
      if(%obj.isAIControlled()) 
      {
         $count2 = 1;

         %path = new Path (%trigger.nextCheck + "Path")
         {
	    //create path
	    new Marker("mycheck")
            {
	       canSaveDynamicFields = "1";
               position = %trigger.getTransform();
               rotation = "1 0 0 0";
               scale = "1 1 1";
               seqnum = $count2;
               type = "Normal";
               msToNext = "1000";
               smoothingType = "Linear";
               speed = "60";
            };
	 
	    //created first marker = current checkpoint
	    //set group name
	    $groupName = %trigger.nextCheck;
            $group = nameToID(%groupName);
            //check if it is valid

            if ($group != -1)
            {
               //get items
               %count = $group.getCount();
               if (%count != 0)
               {
                  while (%count != 0)
                  {
                     //get selected object
                     %spawn = $group.getObject(%index);
                     //create next marker = next object inside of current checkpoint
                     new Marker (%spawn + "1")
                     {
                        canSaveDynamicFields = "1";
                        position = %spawn.getTransform();
                        rotation = "1 0 0 0";
                        scale = "1 1 1";
                        seqnum = $count2;
                        type = "Normal";
                        msToNext = "1000";
                        smoothingType = "Linear";
                     };
                     //created marker
                     //numbers
                     %count = %count - 1;
                     $count2 = $count2 + 1;
                  }
                  // do it again
               }
               else
                  error("No items in " @ %groupName);
            }
            else
               // checkpoint is not valid
               error("Missing spawn points group " @ %groupName);
               //create last marker = next checkpoint
	       new Marker("mycheck2") 
               {
	          canSaveDynamicFields = "1";
                  position = %trigger.nextCheck.getTransform();
                  rotation = "1 0 0 0";
                  scale = "1 1 1";
                  seqnum = $count2;
                  type = "Normal";
                  msToNext = "1000";
                  smoothingType = "Linear";
               };
	       //close marker
         };
         //close Path
         MissionCleanup.add(%path);
      }
      //close if

      //Bot
      $pos = getWords( ServerConnection.getControlObject().getTransform(),0,2);
      if(%trigger.isLast)
      {
         // Player has completed a lap.
         %obj.client.lap++;
         centerPrint(%obj.client, "Lap complete!", 1, 1);

         if(%obj.client.lap >= $Game::Laps)
         {
            centerPrint(%obj.client, "Complete!", 1, 1);
            // Increase his score by 1.
            %obj.client.incScore(1);
            // End the game
            cycleGame();
         }
         else
         {
            %obj.client.nextCheck = 1;
            commandToClient(%obj.client, 'IncreaseLapCounter');
         }
      }
      else
      {
         // Continue to the next one.
         clientCmdCheck();
         %obj.client.nextCheck++;
      }
   }
   else
      centerPrint(%obj.client, "Wrong Checkpoint!", 1, 1);
}

Maybe try declaring the following outside of your path creation loop:

//created first marker = current checkpoint
	    //set group name
	    $groupName = %trigger.nextCheck;
            $group = nameToID(%groupName);
            //check if it is valid
#8
10/05/2007 (3:06 am)
Now I changed it:
//-----------------------------------------------------------------------------
// Torque Game Engine
// Copyright (C) GarageGames.com, Inc.
//-----------------------------------------------------------------------------

datablock TriggerData(CheckPointTrigger)
{
   // The period is value is used to control how often the console
   // onTriggerTick callback is called while there are any objects
   // in the trigger.  The default value is 100 MS.
   tickPeriodMS = 100;
};

//-----------------------------------------------------------------------------

function CheckPointTrigger::onEnterTrigger(%this,%trigger,%obj)
{
   Parent::onEnterTrigger(%this,%trigger,%obj);

   if(%obj.client.nextCheck == %trigger.checkpoint)
   {
      centerPrint(%obj.client, "Checkpoint!", 1, 1);
      //Bot
      // Check AI
      if(%obj.isAIControlled()) 
      {
         $count2 = 1;
 $groupName = %trigger.nextCheck;
            $group = nameToID($groupName);
         %path = new Path (%trigger.nextCheck + "Path")
         {
	    //create path
	    new Marker("mycheck")
            {
	       canSaveDynamicFields = "1";
               position = %trigger.getTransform();
               rotation = "1 0 0 0";
               scale = "1 1 1";
               seqnum = $count2;
               type = "Normal";
               msToNext = "1000";
               smoothingType = "Linear";
               speed = "60";
            };
	 
	    //created first marker = current checkpoint
	    //set group name
	   
            //check if it is valid

            if ($group != -1)
            {
               //get items
               %count = $group.getCount();
               if (%count != 0)
               {
                  while (%count != 0)
                  {
                     //get selected object
                     %spawn = $group.getObject(%index);
                     //create next marker = next object inside of current checkpoint
                     new Marker (%spawn + "1")
                     {
                        canSaveDynamicFields = "1";
                        position = %spawn.getTransform();
                        rotation = "1 0 0 0";
                        scale = "1 1 1";
                        seqnum = $count2;
                        type = "Normal";
                        msToNext = "1000";
                        smoothingType = "Linear";
                     };
                     //created marker
                     //numbers
                     %count = %count - 1;
                     $count2 = $count2 + 1;
                  }
                  // do it again
               }
               else
                  error("No items in " @ %groupName);
            }
            else
               // checkpoint is not valid
               error("Missing spawn points group " @ %groupName);
               //create last marker = next checkpoint
	       new Marker("mycheck2") 
               {
	          canSaveDynamicFields = "1";
                  position = %trigger.nextCheck.getTransform();
                  rotation = "1 0 0 0";
                  scale = "1 1 1";
                  seqnum = $count2;
                  type = "Normal";
                  msToNext = "1000";
                  smoothingType = "Linear";
               };
	       //close marker
         };
         //close Path
         MissionCleanup.add(%path);
      }
      //close if

      //Bot
      $pos = getWords( ServerConnection.getControlObject().getTransform(),0,2);
      if(%trigger.isLast)
      {
         // Player has completed a lap.
         %obj.client.lap++;
         centerPrint(%obj.client, "Lap complete!", 1, 1);

         if(%obj.client.lap >= $Game::Laps)
         {
            centerPrint(%obj.client, "Complete!", 1, 1);
            // Increase his score by 1.
            %obj.client.incScore(1);
            // End the game
            cycleGame();
         }
         else
         {
            %obj.client.nextCheck = 1;
            commandToClient(%obj.client, 'IncreaseLapCounter');
         }
      }
      else
      {
         // Continue to the next one.
         clientCmdCheck();
         %obj.client.nextCheck++;
      }
   }
   else
      centerPrint(%obj.client, "Wrong Checkpoint!", 1, 1);
}
and this is my log:
Compiling Game/server/scripts/checkpoint.cs...
Game/server/scripts/checkpoint.cs Line: 51 - parse error
>>> Advanced script error report.  Line 51.
>>> Some error context, with ## on sides of error halt:
               msToNext = "1000";

               smoothingType = "Linear";

               speed = "60";

            };

^ 

^    //created first marker = current checkpoint

^    //set group name

^   

            //check if it is valid



            if ($group != -1)

## ##           {

               //get items

               %count = $group.getCount();

               if (%count != 0)

               {

                  while (%count != 0)

                  {

                     //get selected object

                     %spawn = $group.getObject(%index);
>>> Error report complete.
#9
10/05/2007 (3:16 am)
To me that says that you should not have anything in the section where you create the path. Create the path, close it off and place anything else you need outside of it.
#10
10/05/2007 (3:24 am)
But I need to create the path in this section. Or is there another solution for my problem?
#11
10/05/2007 (7:28 am)
Yes, its called the add method.

Try this:
//-----------------------------------------------------------------------------
// Torque Game Engine
// Copyright (C) GarageGames.com, Inc.
//-----------------------------------------------------------------------------

datablock TriggerData(CheckPointTrigger)
{
   // The period is value is used to control how often the console
   // onTriggerTick callback is called while there are any objects
   // in the trigger.  The default value is 100 MS.
   tickPeriodMS = 100;
};

//-----------------------------------------------------------------------------

function CheckPointTrigger::onEnterTrigger(%this,%trigger,%obj)
{
   Parent::onEnterTrigger(%this,%trigger,%obj);

   if(%obj.client.nextCheck == %trigger.checkpoint)
   {
      centerPrint(%obj.client, "Checkpoint!", 1, 1);
      //Bot
      // Check AI
      if(%obj.isAIControlled()) 
      {
         $count2 = 1;
         $groupName = %trigger.nextCheck;
         %group = nameToID($groupName);
         %path = new Path (%trigger.nextCheck + "Path");
         
          //create path
         %marker = new Marker("mycheck")
            {
               canSaveDynamicFields = "1";
               position = %trigger.getTransform();
               rotation = "1 0 0 0";
               scale = "1 1 1";
               seqnum = $count2;
               type = "Normal";
               msToNext = "1000";
               smoothingType = "Linear";
               speed = "60";
            };
         [b]%path.add(%marker);[/b]
	 
	      //created first marker = current checkpoint
	      //set group name
	   
         //check if it is valid

         if ($group != -1)
         {
            //get items
            %count = $group.getCount();
            if (%count != 0)
            {
               while (%count != 0)
               {
                  //get selected object
                  %spawn = $group.getObject(%index);
                  //create next marker = next object inside of current checkpoint
                  %marker = new Marker (%spawn + "1")
                  {
                     canSaveDynamicFields = "1";
                     position = %spawn.getTransform();
                     rotation = "1 0 0 0";
                     scale = "1 1 1";
                     seqnum = $count2;
                     type = "Normal";
                     msToNext = "1000";
                     smoothingType = "Linear";
                  };
                  [b]%path.add(%marker);[/b]
                  //created marker
                  //numbers
                  %count = %count - 1;
                  $count2 = $count2 + 1;
               }
               // do it again
            }
            else
               error("No items in " @ %groupName);
          }
          else
            // checkpoint is not valid
            error("Missing spawn points group " @ %groupName);
          //create last marker = next checkpoint
          %marker = new Marker("mycheck2") 
               {
                  canSaveDynamicFields = "1";
                  position = %trigger.nextCheck.getTransform();
                  rotation = "1 0 0 0";
                  scale = "1 1 1";
                  seqnum = $count2;
                  type = "Normal";
                  msToNext = "1000";
                  smoothingType = "Linear";
               };
	   //close marker
	   [b]%path.add(%marker);[/b]
         MissionCleanup.add(%path);
      }
      //close if

      //Bot
      $pos = getWords( ServerConnection.getControlObject().getTransform(),0,2);
      if(%trigger.isLast)
      {
         // Player has completed a lap.
         %obj.client.lap++;
         centerPrint(%obj.client, "Lap complete!", 1, 1);

         if(%obj.client.lap >= $Game::Laps)
         {
            centerPrint(%obj.client, "Complete!", 1, 1);
            // Increase his score by 1.
            %obj.client.incScore(1);
            // End the game
            cycleGame();
         }
         else
         {
            %obj.client.nextCheck = 1;
            commandToClient(%obj.client, 'IncreaseLapCounter');
         }
      }
      else
      {
         // Continue to the next one.
         clientCmdCheck();
         %obj.client.nextCheck++;
      }
   }
   else
      centerPrint(%obj.client, "Wrong Checkpoint!", 1, 1);
}
#12
10/05/2007 (11:26 am)
Sorry, but now I've got a problem: I cannot get my Bot.
I created a Bot in game.cs:
function onServerCreated()
{
...
 %botConnection = aiConnect("MasterBlaster" @ %i, -1, 0.5, false, "SDF", 1.0);
%botConnection.name = "Masterblaster";
%botConnection.path = "CarPath";
}
...
function startRace()
{
// Inform the client we're starting up
   for( %clientIndex = 0; %clientIndex < ClientGroup.getCount(); %clientIndex++ ) {
      %cl = ClientGroup.getObject( %clientIndex );
      commandToClient(%cl, 'GameStart');
...
	  if(%cl.isAIControlled())
         %cl.car.followPath("CarPath", -1);
...
}
...

and now I want to check if the object that enters the trigger is AIControlled. How do I do that?
if(%obj.isAIControlled())
does not work.
and how do I give the bot the command followPath?
Sorry, but I don't know much about ClientConnections and so on...
#13
10/06/2007 (3:46 am)
IsAIControlled doesnt actually do anything anymore. At least not in 1.5.2, its broken (I'm about to fix mine now that I found out). It is only set by the AiConnection which isn't used anymore. What I did (and I got the idea from some resource or post or something) is this:

aiConnect doesn't do anything either all of the AIConnection stuff was ripped out. If you are using an earlier version of TGE then I can't help you. I'm only familiar with my version (1.5.2). If you are using it or an equivalent then you need to create your AI some other way...

Try this article on the TDN: Getting Started With AI

In order to keep track of who is AI and who isn't you can use the example below as a guide. Its how I was doing it...
// create a new AI player
// this is pulled from the TDN article
%newAIPlayer = new AIPlayer(Bob) { datablock = "PlayerBody"; position = LocalClientConnection.camera.getPosition(); };
// set a script variable that says this object is an AI Bot
[b]%newAIPlayer.isAIBot = true;[/b]

    ...
//---------------------------------
    ...

// to test...
if (%someObject.isAIBot)
    ... do something
#14
10/06/2007 (3:52 am)
I now fixed it and it does work fine. I'm using Torque 1.5.2, too. But I've got another problem: The path isn't created. This is my current code:
//-----------------------------------------------------------------------------
// Torque Game Engine
// Copyright (C) GarageGames.com, Inc.
//-----------------------------------------------------------------------------

datablock TriggerData(CheckPointTrigger)
{
   // The period is value is used to control how often the console
   // onTriggerTick callback is called while there are any objects
   // in the trigger.  The default value is 100 MS.
   tickPeriodMS = 100;
};

//-----------------------------------------------------------------------------

function CheckPointTrigger::onEnterTrigger(%this,%trigger,%obj)
{
   Parent::onEnterTrigger(%this,%trigger,%obj);

   if(%obj.client.nextCheck == %trigger.checkpoint)
   {
      centerPrint(%obj.client, "Checkpoint!", 1, 1);
      //Bot
      // Check AI
    echo(%this);
	echo(%trigger);
	  if (%obj.client.isAIControlled())
      {
	  echo("Yes");
	
         $count2 = 1;
         $groupName = "MissionGroup/" + %trigger.nextCheck;
         %group = nameToID($groupName);
         %path = new Path ("roadtotrigger");
         MissionCleanup.add(%path);
          //create path
         %marker = new Marker("mycheck")
            {
               canSaveDynamicFields = "1";
               position = %trigger.getTransform();
               rotation = "1 0 0 0";
               scale = "1 1 1";
               seqnum = $count2;
               type = "Normal";
               msToNext = "1000";
               smoothingType = "Linear";
               speed = "60";
            };
         %path.add(%marker);
		 MissionCleanup.add(%marker);
	 
	      //created first marker = current checkpoint
	      //set group name
	   
         //check if it is valid
%groupName = %obj.client.nextCheck;
echo(%obj.client.nextCheck);
   %group = nameToID(%groupName);
         if (%group != -1)
         {
            //get items
            %count = %group.getCount();
            if (%count != 0)
            {
               while (%count != 0)
               {
                  //get selected object
                  %spawn = %group.getObject(%index);
                  //create next marker = next object inside of current checkpoint
                  %marker = new Marker (%spawn + "1")
                  {
                     canSaveDynamicFields = "1";
                     position = %spawn.getTransform();
                     rotation = "1 0 0 0";
                     scale = "1 1 1";
                     seqnum = $count2;
                     type = "Normal";
                     msToNext = "1000";
                     smoothingType = "Linear";
                  };
                  %path.add(%marker);
				  MissionCleanup.add(%marker);
                  //created marker
                  //numbers
                  %count = %count - 1;
                  $count2 = $count2 + 1;
               }
               // do it again
            }
            else
               error("No items in " @ %groupName);
          }
          else
            // checkpoint is not valid
            error("Missing spawn points group " @ %groupName);
          //create last marker = next checkpoint
          %marker = new Marker("mycheck2") 
               {
                  canSaveDynamicFields = "1";
                  position = %trigger.next.getTransform();
                  rotation = "1 0 0 0";
                  scale = "1 1 1";
                  seqnum = $count2;
                  type = "Normal";
                  msToNext = "1000";
                  smoothingType = "Linear";
               };
	   //close marker
	   %path.add(%marker);
	   MissionCleanup.add(%marker);
         MissionCleanup.add(%path);
      }
      //close if
%obj.client.car.followPath(%trigger.getTransform(), -1);
      //Bot
      $pos = getWords( ServerConnection.getControlObject().getTransform(),0,2);
      if(%trigger.isLast)
      {
         // Player has completed a lap.
         %obj.client.lap++;
         centerPrint(%obj.client, "Lap complete!", 1, 1);

         if(%obj.client.lap >= $Game::Laps)
         {
            centerPrint(%obj.client, "Complete!", 1, 1);
            // Increase his score by 1.
            %obj.client.incScore(1);
            // End the game
            cycleGame();
         }
         else
         {
            %obj.client.nextCheck = 1;
            commandToClient(%obj.client, 'IncreaseLapCounter');
         }
      }
      else
      {
         // Continue to the next one.
         clientCmdCheck();
         %obj.client.nextCheck++;
      }
   }
   else
      centerPrint(%obj.client, "Wrong Checkpoint!", 1, 1);
}
#15
10/06/2007 (4:31 am)
Are you implying that your "echo("Yes")" never happens?

If so I believe it is the problem with the isAIControlled method not doing anything though I could be wrong.
Try adding the code I suggested above for checking if a player is an ai or not. I know that method definately works because you will never set your test variable on a real player (or any object other than an AI).


If 'Yes' is echoed than I'm not sure what the problem is...
#16
10/06/2007 (4:58 am)
Yes is echoed, this is my log:
52
1695
Yes
1
Missing spawn points group 1
followPath()
AIWheeledVehicle::followPath failed - Bad Path!
Just a few things I think/thought about:
it's not possible to create elemts inside a trigger element, so I had to create a Simgroup with my items.
The Simgroup is named %obj.client.nextCheck and I think the problem is, that the programm is not able to get all items inside.
#17
10/06/2007 (5:12 am)
I think this might be your problem:
$groupName = "MissionGroup/" + %trigger.nextCheck;

should be:

$groupName = "MissionGroup/"[b] @ [/b]%trigger.nextCheck;

Weird.. it wont embolden only the '@' character by itself..
#18
10/06/2007 (5:19 am)
Result:
52
1696
Yes
2
Missing spawn points group 2
followPath()
AIWheeledVehicle::followPath failed - Bad Path!
Game/server/scripts/checkpoint.cs (140): Unable to find function clientCmdCheck
52
1697
Yes
3
Game/server/scripts/checkpoint.cs (62): Unknown command getCount.
  Object AudioDefault3d(3) AudioDescription -> SimDataBlock -> SimObject
No items in 3
followPath()
AIWheeledVehicle::followPath failed - Bad Path!
#19
10/06/2007 (6:00 am)
What is the name of the actual group that the triggers are located in?

Right now it is looking in a group named "MissionGroup/2".

Where are your triggers located? It says that there is no group named "2".
#20
10/06/2007 (6:03 am)
The triggers are located under: MissionGroup
the items are located under: MissionGroup/1, MissionGroup/2, MissionGroup/3...
Page «Previous 1 2