AIPlayer, datablock, subclass question
by Bert Rosell · in Torque Game Engine · 02/06/2004 (7:12 am) · 3 replies
I'm trying to create NPC type objects. Here is how I (partially) implemented it.
What I wanted to happen was have the NPC face the player when the player bumped into it. But the console says this:
My question is how can I convince the NPC to call methods of AIPlayer? I thought that since I "new'd" an AIPlayer, that would do it.
(I'm using the tutorial.base tree and have brought over aiPlayer.cs.)
Edit:
If I do a
When I do a
datablock PlayerData(NPC : PlayerShape)
{
category = "NPC";
cmdCategory = "NPCs";
name = "Joe";
pushable = true;
};
function NPC::create()
{
echo("newing AIPlayer for NPC");
%obj= new AIPlayer()
{
datablock= NPC;
};
echo("NPC created");
%obj.dump();
return %obj;
}
function NPC::onAdd(%this, %obj)
{
echo("NPC added");
}
function NPC::onCollision(%this, %obj, %col, %pos)
{
// %obj - instance of object that got hit
// %col - object collision occured with
// %pos - locaiton of collision (x y z)
echo("obj is " @ %obj.name);
echo("this is " @ %this.name);
echo("col is " @ %col.name);
if (%col.name $= "Hank")
{
echo ("Hi Hank!");
echo (%col.getPosition());
}
%this.setAimObject(%col);
}What I wanted to happen was have the NPC face the player when the player bumped into it. But the console says this:
tutorial.base/server/NPC.cs (45): Unknown command setAimObject. Object NPC(52) NPC -> PlayerData -> ShapeBaseData -> GameBaseData -> SimDataBlock -> SimObject
My question is how can I convince the NPC to call methods of AIPlayer? I thought that since I "new'd" an AIPlayer, that would do it.
(I'm using the tutorial.base tree and have brought over aiPlayer.cs.)
Edit:
If I do a
%obj.dump()in NPC::create, the setAimObject method is listed.
When I do a
%this.dump()in NPC::onCollision(...) the setAimObject method is not listed.
#2
02/06/2004 (2:04 pm)
Yeah i guess the same thing - you create one instance of the datablock when you define it and that will then get used for all the NPCs you instantiate using it...
#3
02/06/2004 (3:18 pm)
%this is your PlayerData datablock and %obj is your AIPlayer instance. You can create multiple objects using the same datablock. It's kind of like a set of initialization parameters.
Torque Owner Bert Rosell
I was able to call %obj.setAimObject(...) successfully.
I guess (and correct me if I'm wrong) that %this is the datablock for ALL NPCs.
-thanks for looking.