Game Development Community

Hate to seem like I am spamming this Topic...

by Jeff Trier · in Torque Game Engine · 03/17/2003 (10:22 pm) · 6 replies

lol, It seems like I am just spamming this section of the forum with questions. Too bad more people didn't ask questions here so it would dilute my appearance. :)

Anywho, I am having a problem and I just can't figure it out....

When I spawn my AI, it will run the AiNewSpawn AudioProfile as it should, but when I kill the AI it wont run the AiDeathCrySound AudioProfile. Instead, it will display "Unknown command playAudio" (in the console) when it runs function AIPawn::onDeath(%this, %obj), which is strange because to me that means it isn't recognizing it as a command, which it should because it just used it. Is this a bug?

Here are some visual aids:


(Paste from console)
I died as Pawn!
fps/server/scripts/AIpawn.cs (706): Unknown command playAudio.
Object (1534) Projectile -> GameBase -> SceneObject -> NetObject -> SimObject

Functions Used
datablock AudioProfile(AiNewSpawn)
{
   fileName = "~/data/sound/ready1.wav";
   description = AudioDefault3d;
   preload = true;
};

datablock AudioProfile(AiDeathCrySound)
{
   fileName = "~/data/sound/death1.wav";
   description = AudioDefault3d;
   preload = true;
};


function AIPawn::onAdd(%this,%obj)
{
	echo("I Exist as Pawn!");
	%obj.playAudio(1,AiNewSpawn);

   // Vehicle timeout
   %obj.mountVehicle = true;

   // Default dynamic armor stats
   %obj.setRechargeRate(%this.rechargeRate);
   %obj.setRepairRate(0);

}

function AIPawn::onDeath(%this, %obj)
{
   // Inform the client
	echo("I died as Pawn!");
	%obj.playAudio(1,AiDeathCrySound);
}

About the author

Originally a Classical/Metal musician, I've always been attracted to anything involving computers, including: Networking, PC Building and Repair, software design and coding. I've been involved with game design and development for over 10 years.


#1
03/18/2003 (12:21 am)
I'm guessing its because %obj is the projectile thats killed your pawn, not the pawn itself.

try %this.playaudio and see what happens?

Phil.
#2
03/18/2003 (5:33 am)
Hi Phil,

You know, I thought it should have been %this since I read that the Datablock gets sent to the first argument of a function:

Quote:
The arguments need a bit of explaining. When you call a datablock's function with the dot operator, the datablock is automatically sent to the function as the first argument. In this example, within the MyFunction function, the variable %obj would reference a datablock. For this reason, it is common practice to declare datablock functions with the first variable as %obj.

So I tried that first and it gave me the same error. Then oddly enough, %obj worked, but only on the OnAdd function. So there must be some rule I missed.

So now I have two questions:

1) What is the above quote missing about passing Arguments.
2) Why would I get a "Unknown command playAudio" error when it will use it sometimes.

[EDIT: Clean Up]

Thanks,
-Jeff
#3
03/18/2003 (5:54 am)
I don't know where you found this onDeath function, but usually "onDeath" seems to have more than two parameters...
I have a custon "onDeath" function for my bots which looks like this:
function Armor::onDeath(%this, %obj, %sourceObject, %sourceClient, %damageType, %damLoc)
{
   echo("%this:" SPC %this SPC "%obj:" SPC %obj SPC "%sourceObject:" SPC %sourceObject SPC "%sourceClient:" SPC %sourceClient SPC "%damageType:" SPC %damageType SPC "%damLoc:" SPC %damLoc);
   if (%damageType $= "Suicide" || %sourceClient == %sourceObject) {
      messageAll('MsgClientKilled','%1 takes his own life!',%sourceObject.getShapeName());
   }
   else
   {
      %killObject = %sourceClient;
      if (%killObject $= "") %killObject = %sourceObject.sourceObject;
      %killObject.incScore(30);

      %DiedHow = "gets fragged by";
      if (%damageType $= "RifleBullet")     %DiedHow = "gets capped by";
      if (%damageType $= "MP5a3Bullet")     %DiedHow = "gets gunned down by";
...
// etc.
So I would try it with those parameters and try to use "%sourceObject" to play your audio, this should be the "pawn" in your case...
#4
03/18/2003 (6:18 am)
Jeff,

You are correct. The first arguement is the object itself, but you are incorrect in assuming that the first arguement will always be %obj.

In some instances it is %this, in others it is %obj, and still in others it is something entirely different.

As it so happens, the onDeath's first arguement is %this, following by %obj, so in this function you want to use %this, not %obj because %obj in this instance is refering to the projectile.

It is kind of confusing I know, but it helps a great amount if you pay attention to the order of the arguements in the functions you are calling.

For this very reason the dev group I'm involved with went through the entire scripts and renamed all the arguements to the functions to be consistent throughout, with better naming schemes. You might want to look into doing the same, kind of boring though :)
#5
03/18/2003 (6:40 am)
For the life of me, I couldn't find an OnDeath "function" (only things like %client.onDeath(%this, %obj, %sourceObject, %sourceClient, %damageType, %damLoc);), so I had to create one. I searched in Player.cs and the rest of the files. But due to my lameness, I have a feeling it was/is there and I missed it.

Hmmm... I guess to understand AI better I would like to ask, how does a bot actually get it's attributes? Does it first create a shell of sorts through "AIPlayer::spawnPlayer", then grabs all of its attributes through any function or datablock that has the target datablock name?

For instance if it has "dataBlock = pawn;", will it use EVERY function, in any file, with Pawn::somefunction attached to it? If so, is it best to have the main shell of the AIPlayer::spawnPlayer function on one .cs, then have a .cs for every other class for it to pull from (sniper.cs, Priest.cs, Barbarian.cs)?


Thanks,
-Jeff
#6
03/18/2003 (6:48 am)
Thanks Robert :)


So, is the second Argument of any current function, a passing of a variable from the function that called it (hope that made sense)?

Thanks for the idea's on renaming. When I learn a bit more, I may do just that. Currently I am reading everything I can about this engines syntax and symantics, rough going with the docs available.

Thank god for the community... lol


-Jeff