Getting a list of RTS units (RTS Pack)
by Hadi Aggoune · in Torque Game Engine · 07/08/2006 (3:05 pm) · 0 replies
Hey, guys. I've run into some trouble. What i'm doing is I have some units that are going to be driven by an outside data source. I have position and attitude (in angle-axis) coming into the simulation just fine. My plan was to pass the data and a list of the local connection's RTS units to a script function that would parse the data out and use the objects setTransform() methods to manipulate them. I'm doing some of this in script since it looks easier that way, correct me if I'm wrong. I can probably do it in the engine code if need be.
So i have the server set up to listen for these special position packets, which are handled in a function i added to NetInterface called handlePosPacket(). handlePosPacket() right now just shoots the data to the console and pumps it over to the script function via Con::executef().
The trouble comes in that I need some way of obtaining a list of the local clients units. I looked through RTSConnection and thought I could access them through RTSConnection::getLocalClientConnection, since in gameConnection.cs there is a line that adds the units to a simGroup.
function RTSConnection::onClientEnterGame(%this)
{
commandToClient(%this, 'SyncClock', $Sim::Time - $Game::StartTime);
%unitsPerDir = 4;
// Add to team
%clientIndex = %this.getClientIndex();
%this.setTeam(%clientIndex);
%offset = ((%this.getTeam()-1) * (%unitsPerDir + 5));
// Create simset to track all units
%this.units = new SimGroup();
.
.
.
}
Not sure how it works though since it looks like a dynamic field, I probably couldn't access that from c++.
My handler function looks like:
void NetInterface::handlePosPacket(PacketReceiveEvent *prEvent){
Con::printf("Received Position Data: %s", prEvent->data);
RTSConnection *local = RTSConnection::getLocalClientConnection();
Con::executef(3,"updatePA",prEvent->data,local);
}
I'm not sure exactly how passing objects into torque script works as i'm pretty new to it, but i tried passing the pointer and also passing the object. Either way it says that local is not NULL in handlePosPacket() and it shows up NULL in the script function:
function updatePA(%data,%local)
{
echo("Inside the updatePA script function.");
echo("Recieved: " @ %data);
if(%local)
{
echo("Local is not equal to null!");
}
else
{
echo("Local is null =(");
}
}
So i'm wondering why local is showing up NULL in updatePA, and once I can get it into the script function correctly, will I be able to access that list of units doing something like: %local.units.first() and iterating over it? and if not, if you have any suggestions about obtaining a list of units please feel free.
Any input is appreciated, and thanks in advance.
So i have the server set up to listen for these special position packets, which are handled in a function i added to NetInterface called handlePosPacket(). handlePosPacket() right now just shoots the data to the console and pumps it over to the script function via Con::executef().
The trouble comes in that I need some way of obtaining a list of the local clients units. I looked through RTSConnection and thought I could access them through RTSConnection::getLocalClientConnection, since in gameConnection.cs there is a line that adds the units to a simGroup.
function RTSConnection::onClientEnterGame(%this)
{
commandToClient(%this, 'SyncClock', $Sim::Time - $Game::StartTime);
%unitsPerDir = 4;
// Add to team
%clientIndex = %this.getClientIndex();
%this.setTeam(%clientIndex);
%offset = ((%this.getTeam()-1) * (%unitsPerDir + 5));
// Create simset to track all units
%this.units = new SimGroup();
.
.
.
}
Not sure how it works though since it looks like a dynamic field, I probably couldn't access that from c++.
My handler function looks like:
void NetInterface::handlePosPacket(PacketReceiveEvent *prEvent){
Con::printf("Received Position Data: %s", prEvent->data);
RTSConnection *local = RTSConnection::getLocalClientConnection();
Con::executef(3,"updatePA",prEvent->data,local);
}
I'm not sure exactly how passing objects into torque script works as i'm pretty new to it, but i tried passing the pointer and also passing the object. Either way it says that local is not NULL in handlePosPacket() and it shows up NULL in the script function:
function updatePA(%data,%local)
{
echo("Inside the updatePA script function.");
echo("Recieved: " @ %data);
if(%local)
{
echo("Local is not equal to null!");
}
else
{
echo("Local is null =(");
}
}
So i'm wondering why local is showing up NULL in updatePA, and once I can get it into the script function correctly, will I be able to access that list of units doing something like: %local.units.first() and iterating over it? and if not, if you have any suggestions about obtaining a list of units please feel free.
Any input is appreciated, and thanks in advance.