Game Development Community

Objects in mission file not in MissionGroup

by Justin Tolchin · in RTS Starter Kit · 03/09/2005 (11:22 am) · 3 replies

Hi all,

Kind of a weird problem here. I'm trying to get objects loaded from the mission file to get initialized properly with the client connection information. To do this I added some code into the RTSConnection::onClientEnterGame script:

...
...
echo("onClientEnterGame: setting client/team info for objects loaded from mission file...");

// add the client connection info to each building in the mission file
for (%i = 0; %i < MissionGroup.getCount(); %i++)
{
	%obj = MissionGroup.getObject(%i);
	if (%obj.getClassName() $= "RTSBuilding") 
	{
		echo("onClientEnterGame: found building" SPC %obj.getRTSUnitTypeName() SPC "in mission file. setting client info.");
		%obj.client = %this;
		%obj.setTeam(%obj.team);
		%obj.setControllingConnection(%this);
		%this.buildings.add(%obj);
	}
	else if (%obj.getClassName() $= "RTSUnit") 
	{
		echo("onClientEnterGame: found unit" SPC %obj.getRTSUnitTypeName() SPC "in mission file. setting client info.");
		%obj.client = %this;
		%obj.setTeam(%obj.team);
		%obj.setControllingConnection(%this);
		%this.units.add(%obj);
	}
	else
		echo("skipping object" SPC %obj);
}
echo("onClientEnterGame: finished setting client/team info for objects loaded from mission file.");

What I'm seeing is that all the objects load in fine except the last RTSBuilding. Consequently the VisManager crashes because the client connection is missing from that one building. I thought maybe it just wasn't processing whichever was the last RTSBuilding in the file, so I took that building out of the mission file, but then everything loaded fine. So much for that theory. So then I thought maybe something was odd about that particular building class, but then I added it back in and put another building type *after* it in the mission file. Then the previously non-working building started working fine and the newly added building didn't get it's info added. :-( So there's nothing wrong with the building classes themselves, there's just something being left out of the MissionGroup sometimes (that's nice and vague, I know).

The last section of my mission file looks like this:

...
...
<various unit and building types here>
...
...
   new RTSBuilding() {
      position = "-44.96 -24.8554 400";
      rotation = "1 0 0 0";
      scale = "1 1 1";
      dataBlock = "refineryBlock";
         client = "1458";
         mountVehicle = "1";
         team = "0";
   };
   new RTSBuilding() {
      position = "-67.76 -29.8554 400";
      rotation = "1 0 0 0";
      scale = "1 1 1";
      dataBlock = "bcTowerBlock";
         client = "1458";
         mountVehicle = "1";
         team = "0";
   };

Here is what I see in the console.log:

onClientEnterGame: setting client/team info for objects loaded from mission file...
skipping object 1466
skipping object 1467
skipping object 1468
skipping object 1469
skipping object 1470
skipping object 1471
skipping object 1472
onClientEnterGame: found building tent in mission file. setting client info.
<bunch of other buildings here...>
onClientEnterGame: found building refinery in mission file. setting client info.
onClientEnterGame: finished setting client/team info for objects loaded from mission file.

Notice that the bcTower building is not getting processed. I do see it get sent to the RTSUnitData::onAdd method (I just print out the object id's in that method), but somehow it never gets processed in the MissionGroup loop above. I'm also printing out the object id's for the objects that get "skipped" and I never see the id for the bcTower. Anyone have any theories about where this sucker is getting lost?

Thanks!

#1
03/10/2005 (10:47 am)
Ok, figured out my problem. I realized at a certain point that when I iterated through the MissionGroup (SimGroup) that there were supposed to be 36 objects in there, but it was only iterating through 23 of them. The reason was because of the lines:

%this.units.add(%obj);

and

%this.buildings.add(%obj);

Both "units" and "buildings" were supposed to be SimSets (at least according to the comment above them) but they were created as SimGroups...

// Create simset to track all units
%this.units = new SimGroup();

Since an object can only exist in one SimGroup at a time, as soon as they got added to "buildings" or "units" they got removed from MissionGroup, and removing objects from a list is a bad thing to do when you're iterating through the list. :-)

Anyway, changing those 2 SimGroups into SimSets solved my problem.

This seems like something that ought to be fixed in the kit.
#2
03/10/2005 (10:57 am)
Now you see why the choice between simSet and simGroup is one I harp on ALL the time! While not directly on point, this bug post about MissionCleanup group describes why it is happening.

Great catch...those are extremely difficult to figure out since the removal from the previous group is silent!
#3
02/28/2008 (2:16 pm)
Sorry to pull up this old thread but i am getting the same problem what did you mean by changing them to simsets? you mean changing
// Create simset to track all units
%this.units = new SimGroup();

// Create simset to track all buildings
%this.buildings = new SimGroup();

to

// Create simset to track all units
%this.units = new SimSet();

// Create simset to track all buildings
%this.buildings = new SimSet();

because that did not work for me.