Parent Datablock
by Derk Adams · in Torque Game Engine · 12/19/2004 (5:53 am) · 6 replies
Greetings,
I am working in aiplayer.cc and need to return the parent datablock instead of the current datablock. I.e. in the structure DemoPlayer -> AIPlayer -> Player -> etc., I want to execute the script AIPlayer::onReachDestination instead of DemoPlayer::onReachDestination.
The code in question is:
How do I change "getDataBlock()" to point to the parent datablock?
Thanks.
I am working in aiplayer.cc and need to return the parent datablock instead of the current datablock. I.e. in the structure DemoPlayer -> AIPlayer -> Player -> etc., I want to execute the script AIPlayer::onReachDestination instead of DemoPlayer::onReachDestination.
The code in question is:
void AIPlayer::throwCallback( const char *name )
{
Con::executef(getDataBlock(), 2, name, scriptThis());
}How do I change "getDataBlock()" to point to the parent datablock?
Thanks.
About the author
#2
But, the question is... why do you want to return it for the whole AIPlayer class rather than for the specific AI defined by DemoPlayer?
- Brett
12/20/2004 (5:44 am)
Change it to scriptThis and you should get what you want. Although, you may not have that variable defined for AIPlayer. Look for "scriptThis" in code and duplicate it for AIPlayer.But, the question is... why do you want to return it for the whole AIPlayer class rather than for the specific AI defined by DemoPlayer?
- Brett
#3
All the "scriptThis" code points to the current datablock. I want to get the level above it.
I will have on the order of hundreds of datablocks (right now I only have two). I want them to execute either the Player functions or AIPlayer functions depending on their creation. Otherwise, I have to have copy functions for every individual datablock.
Thanks.
12/20/2004 (9:14 am)
Brett,All the "scriptThis" code points to the current datablock. I want to get the level above it.
I will have on the order of hundreds of datablocks (right now I only have two). I want them to execute either the Player functions or AIPlayer functions depending on their creation. Otherwise, I have to have copy functions for every individual datablock.
Thanks.
#4
03/09/2009 (2:25 am)
Derek, have you ever sorted out this problem. I'm having trouble with some AI stuff myself.
#5
what problems you having? I've been messing a bit with AI lately, and my AI call all their own functions.
03/09/2009 (8:52 am)
@James,what problems you having? I've been messing a bit with AI lately, and my AI call all their own functions.
#6
Here is a part of the scout script:
The function gets called though. And %Obj is the Datablock ID(eg 2265). But %obj.client is empty when onReachDestination is called.
Now here's the code:
So in code things changed to:
Here's the script for when a a ship spawns in script:
03/10/2009 (5:01 am)
I'm having troubles with the callbacks for AIFlyingVehicles (the onReachDestination specifically. Now the old resource didn't even move. Got that working. In Solar Battles it's just that %obj.client is empty and I can't seem to figure out why.Here is a part of the scout script:
function sScout::onReachDestination(%this, %obj)
{
if (%obj.client.isAIControlled()) // if ai, then do some action
%obj.client.aiSetDestinationReached(true);
}
..
..
..
datablock FlyingVehicleData(ScoutShip)
{
spawnOffset = "0 0 0"; // spawn offset if needed
category = "Vehicles"; // category for the editor
[b]className = sScout;[/b] // our script class namespaceThe function gets called though. And %Obj is the Datablock ID(eg 2265). But %obj.client is empty when onReachDestination is called.
Now here's the code:
void AIFlyingVehicle::throwCallback( const char *name )
{
Con::executef(getDataBlock(), name, scriptThis());
}So in code things changed to:
void AIFlyingVehicle::throwCallback( const char *name )
{
Con::executef(getDataBlock(), name, scriptThis());
} which should work. It does for the AIPlayer.Here's the script for when a a ship spawns in script:
%player = new aiFlyingVehicle()
{
dataBlock = %shipType;
[b]client = %this;[/b]
};
MissionCleanup.add(%player);Stepping through this the client does get set, so I'm not sure what else I need to be looking into.
Torque Owner Derk Adams