Game Development Community

Global Variables

by Derk Adams · in Torque Game Engine · 12/20/2004 (5:48 am) · 3 replies

Greetings,

And hopefully Gonzo will be lurking around here :)

I am using a global variable to hold all of the player and bot objects:

$allPlayers = new SimGroup(allPlayers);

and I load this in server/scripts/game.cs under startGame.

When creating the Bots in /server/scripts/aiPlayer.cs I send the object id at the end of the spawn function (this part works fine). In /server/s/game.cs I also add the player id at the end of GameConnection::createPlayer. I even check the size of $allPlayers before and after adding the player. I get a total of two after the bots and a total of three after the player, but when accesing the simgroup for targeting purposes, there are only the two bot ids and the size is 2.

So first question, is there a better way to keep the player and bot ids?

If not, what is happening to my player id which is getting added, but ends up missing?

Thanks.

#1
12/20/2004 (5:59 am)
Your main issue here is that you are using a SimGroup, and not a SimSet.

SimGroups are a child of SimSets, with one unique and special property: a game object may be a member of one and only one SimGroup. There are a couple of reasons behind this, but due to this contraint on SimGroups, any time an object is placed within a SimGroup with .add(%objectID), it is silently removed from any SimGroup it may be a part of already.

In this case, I assume that you are, later in your execution flow, adding your player into a different SimGroup (most probably MissionCleanup, which is part of stock). Most probably, when you create your AI bots, they either aren't being added to the MissonCleanup group at all (bad, a mem leak most likely), or they are added to MissionCleanup first, and then added to your allPlayers--which means they are removed from MissionCleanup, and that is a memory leak therefore as well.
#2
12/20/2004 (9:19 am)
Stephen,

Thank you very much. That was exactly the issue. I appreciate the clarification of the concept. I had copied it from a resource, that apparently is using it incorrectly.

Thanks.
#3
12/20/2004 (9:38 am)
No problem at all--I ran into this exact situation myself a few weeks ago, so it was clear in my mind!