Game Development Community

Dedicated Crashing when creating new AI

by DALO · in General Discussion · 10/17/2008 (12:28 pm) · 5 replies

Hello, I have come across something that is just baffling me. Currently my game works with no bugs, my AI bots spawn and run around just fine. This works for single player, multiplayer LAN and online. When I start a dedicated server, I have all my variables in place and it loads up all my AI scripts as well as starting my AIManager. My AI bots are a class that was inherited from AIPlayer. I also have an AIManager that manages all the bots. The manager loads up just fine and it starts spawning new bots when it needs to, it calls a function in the scripts from the engine to create a new AI Bot. This is were it crashes. When I create the new AI Bot and use a PlayerData datablock (anyone one of 6 possible) it spits out this error:
Quote:AIAgent.cs(32): Unable to find object: '0' attempting to call function (some random function)

So why would this work perfectly fine in client/server mode but dedicated/server mode it can't find any PlayerData datablocks?

Windows XP
TGE 1.5.2

#1
10/17/2008 (1:16 pm)
Would you post lines 17 to 47 of aiAgent.cs?
#2
10/17/2008 (1:26 pm)
Sure, here's the script function that get's called from the engine:
function AIAgent(%isTerrace){
   
   // create the new agent
   if(%isTerrace $= "true"){
      %newAgent = new AIAgent(){
         dataBlock = shadowBot2;
      };
      MissionCleanup.add(%newAgent);

   }else{
      %newAgent = new AIAgent() {
         dataBlock = shadowBot;
      };
      MissionCleanup.add(%newAgent);
   }
     
   return %newAgent;
}

shadowBot/2, and bigBot are PlayerData datablocks that are executed long before any AI code is run. Like I said before, everything works perfectly fine it's just the dedicated server mode won't work. I should mention that once the function is complete I do the rest of the AI Bot setup in the engine by executing this line:
newAgent = dynamic_cast<AIAgent*>(Sim::findObject(id));
id is the returned id of the newAgent that was created in the scripts. I used this method only because I don't know how to create an object in engine and link it with a specific datablock.

Thx.
#3
10/17/2008 (2:27 pm)
Did you mean:
function AIAgent(%isTerrace){
   
   // create the new agent
   if(%isTerrace $= "true"){
      %newAgent = new [b]i[/b]AIAgent(){
         dataBlock = shadowBot2;
      };
      MissionCleanup.add(%newAgent);

   }else{
      %newAgent = new iAIAgent() {
         dataBlock = shadowBot;
      };
      MissionCleanup.add(%newAgent);
   }
     
   return %newAgent;
}
#4
10/17/2008 (3:05 pm)
Ooops, that's was a typo in the post, not in scripts. Does anyone know what is/isn't being executed in dedicated mode, other than the gui? Maybe I can just create the AI agents in engine, how would I do that and be able to link the datablocks to the agents?
Here's a guess:
AIAgent* newAgent = AIAgent();
// how to specify which datablock this new agent is? It's inherited from AIPlayer which is inherited from Player
SimGroup *group = Sim::getDataBlockGroup();
// and then perhaps some looping function to find if it exists
while( size of group...){
   if(groupMember->getName() == "shadowBot) // (pseudo code) 
      then voila, object exists
}
// now how to link the datablock to the newAgent.....if found?
newAgent->Parent::onNewDataBlock( newAgent->mDataBlock-> ????);
Maybe I'm way of base here.....? I'm not really sure how to do this, but if I can at least see if the datablock does exist and maybe just create the bot in engine then......maybe that'll help?
Thx.
#5
10/17/2008 (6:59 pm)
I could be off base too, but possibly, your new child class which is derived from the parent class is attempting to use an ID that is already used.?
It's just a random thought, it's something I would look at if i was debugging it.