Game Development Community

Torque script function arguments

by Ricardo Cabral · in Torque Game Engine · 02/09/2005 (3:20 pm) · 2 replies

I wonder if there is anyway to know what type of argument is being passed in the function arguments ?

i wanted to use getEyeVector on the onFire method of a projectile, because i need the weapon to be fired in the head direction, which can be different from the body, but it seems to me that %obj and %this stand for different things in each method, since i can't use %this.getEyeVector in the onFire method like the following code(drop-in grenade resource):
function ShapeBase::throwObject(%this,%obj){
   // Throw the given object in the direction the shape is
   // looking.  The force values are hardcoded...
   echo("ShapeBase::throwObject grenade, getting direction");
   %eye = %this.getEyeVector();

thanks,
-nd

#1
02/09/2005 (6:41 pm)
Callback functions are assigned to Datablocks rather than objects. So %this is usually the datablock and %obj is the object to whom the datablock belong.

So perhaps you would use %obj.getEyeVector();
#2
02/09/2005 (11:47 pm)
@ Bruno

That is not true in all cases. Performing an action on a datablock can have effects that range from crashing, to funny, to downright mindboggling. For example, if you wanted to cloak a certain object in the game like an ammo clip and you performed the action on the datablock instead of the actuall object, then EVERY ammo clip in the game would cloak at the same time. In the case of "ShapeBase" objects the first variable(%this) will almost always refer to the actuall objectID# and not it's datablock.


In this particular case though, you are correct about the images. In the crossbow example...


CrossbowImage::onFire(%this, %obj, %slot)


%this is the image datablock for the crossbow, %obj is the player holding the crossbow, and %slot is the mountpoint that is firing the weapon(usually "0"). So to get the eye vector in the onFire method you would use...

%obj.getEyeVector();