Game Development Community

difference between %this, %obj in the scripts

by Gabe Zingaretti · in Technical Issues · 01/29/2003 (11:14 am) · 6 replies

Hi all,

could anyone tell me the differnece between %this and %obj in the scripts?

thanks,

Gabe

#1
01/29/2003 (11:34 am)
depends on the context ..
but I would hope that
%this represents the script class you are working with and obj represents the actual object that owns the datablock reference

example:

PlayerData::somefunction(%this, %obj)

%this would be the datablock and %obj would be the actual Player class
#2
01/29/2003 (11:44 am)
thanks so let me understand here is a junk of code:

function CrossbowImage::onFire(%this, %obj, %slot)
{
%projectile = %this.projectile;

// Decrement inventory ammo. The image's ammo state is update
// automatically by the ammo inventory hooks.
%obj.decInventory(%this.ammo,1);

...
..
...

what about if I do %obj.decInventory(%obj.ammo,1); instead

thanks,

Gabe
#3
01/29/2003 (11:48 am)
never mind I think the above example doesn't make sense.

Gabe
#4
01/29/2003 (12:06 pm)
%obj and %this aren't internal names, they mean wherever they've been put.
The real question you are asking is, what do the different parts of the arguments in onFire mean.

First (%this) is the datablock (the crossbow)
The second (%obj) is the player holding the crossbow
The third is, obviously, the slot.

You can't take %this to mean datablock ALL the time, however. I've seen %this be used to represent an object (not a datablock) in a some function somewhere ( I think it was a collision one)
#5
01/29/2003 (1:40 pm)
thanks now it makes more sense...one quick question onFire(...) where does this method get define in the C code. I couldn't find it.

Thanks,

Gabe
#6
01/29/2003 (3:43 pm)
yea its a little nasty...
the ShapeBase object has a state array
and this is one of the functions scripted to be called by it