Game Development Community

How to work with multi-bots ?

by Areal Person · in Torque Game Engine · 08/10/2006 (12:28 pm) · 2 replies

Ok, I got a script to create two bots like the following.
But How do I work with each individule bot ? What function
do I use ? Whats the varaible scope ? and what variable for each bot ?

Now that there on there own path how do I work with each bot ?
use array ?, How to do it ?

should my think function be setup different ?

It's called from game.cs like this
-----------------------------------------
function onMissionLoaded()
{
// Called by loadMission() once the mission is finished loading.
new ScriptObject(AIManager) {};
MissionCleanup.add(AIManager);
AIManager.think(); <-------------------------------------------------------------

}
--------------------------------------------
Thanks,
----------------------------------------
function AIManager::think( %this ) <----------------------------------------
{
if( !isObject( %this.player ) )
%this.player = %this.spawn();

%this.schedule( 500, think );
}

-----------------------------------------
function AIManager::spawn( %this )<----------------------------------------
{

%bot = AIPlayer::spawnOnPath( "Bot_1", "MissionGroup/Path1" );
%bot.followPath( "MissionGroup/Path1", -1 );

%bot = AIPlayer::spawnOnPath( "Bot_2", "MissionGroup/Path2" );
%bot.followPath( "MissionGroup/Path2", -1 );

return %bot;
}

#1
08/10/2006 (1:21 pm)
Hiya -

that definitely won't work.
it would probably be beneficial for you to spend some time figuring out why it won't work, versus just trying it and seeing that it doesn't.

try something like this:
(untested)
function onMissionLoaded()
{
   new ScriptObject(AIManager) {};
   MissionCleanup.add(AIManager);
   AIManager.spawnAll();
   AIManager.think();
}

function AIManager::think(%this)
{
   if (isObject(%this.bots))
   {
      %num = %this.bots.getCount();
      for (%n = 0; %n < %num; %n++)
         %this.bots.getObject(%n).think();
   }
   
   %this.schedule(500, think);
}

function AIManager::spawnAll(%this)
{
   if (!isObject(%this.bots))
      %this.bots = new SimSet();
   
   %bot = AIPlayer::spawnOnPath("Bot_1", "MissionGroup/Path1");
   %bot.followPath("MissionGroup/Path1", -1);
   %this.bots.add(%bot);
   
   %bot = AIPlayer::spawnOnPath("Bot_2", "MissionGroup/Path2");
   %bot.followPath("MissionGroup/Path2", -1);
   %this.bots.add(%bot);
}


function AIPlayer::think(%this)
{
   echo("I am a bot. I am thinking. My ID is" SPC %this SPC "my name is" SPC %this.getShapeName());
}
#2
08/10/2006 (2:20 pm)
Looks good !,

I think the key is %this.bots = new SimSet();

Thats the container.

Thank you.