Game Development Community

why is my ClientGroup.getCount() in startGame 0?

by Ryan Timoney · in Torque 3D Professional · 10/06/2010 (12:34 am) · 2 replies

In the GameCore::startGame fn in gamecore.cs I have added two echos:

echo( "c4 -> prepping "@ClientGroup.getCount()@" clients" );
   for (%clientIndex = 0; %clientIndex < ClientGroup.getCount(); %clientIndex++)
   {
      echo( 'prepped 1 client' );
      %cl = ClientGroup.getObject(%clientIndex);
      commandToClient(%cl, 'GameStart');
      %cl.score = 0;
   }

When the mission loads, it will print " -> prepping 0 clients " and will never print "prepped 1 client." However, once the mission is loaded and I type "echo( clientgroup.getcount() );" it will print "1." Is this because I'm hosting the game? Would it actually be looping through remote clients if they were connected? (If not, why is this here?)

My goal is simply to reset a timer on client guis when certain events occur. It's my understanding I need to loop through the clients the way the code above is supposed to. I want to start the timer when the startGame function is called, but it seems that at that time I don't have a list of all the clients available to me.

#1
10/06/2010 (1:07 am)
I believe that startGame would be called before the engine creates your local client and "connects" it to the server in this case.

The only case in which startGame would be called while clients are connected would likely be if you loaded a new map while players were already connected, either through the timed map switch or by manually calling loadMission("filename");

To test this I'd suggest starting a dedicated server (run your exe with -dedicated -mission filename), connecting to it, and then restarting the mission with loadMission("filename"); from the server console.
#2
10/06/2010 (1:51 am)
Good call. I think you're right - startGame is called by onMissionReset which would make use of the clientGroup loop in that case.

That in mind, I honed in on what I needed: I don't have access to the source files so I'm not sure how clientGroup is actually set, but clientGroup is populated by the time onClientEnterGame is called. Makes sense. Thanks!