Game Development Community

%this call for new t2dStaticSprite

by rennie moffat · in Torque Game Builder · 02/20/2010 (1:32 pm) · 6 replies

function PlayerShip::fireMissile(%this)
{
%this.playerMissile = new t2dStaticSprite()
{
scenegraph = %this.scenegraph;
class = PlayerMissile;
missileSpeed = %this.missileSpeed;
player = %this;
};
%this.playerMissile.fire();
}

I am wondering what the purpose of player = %this is.


Does %this, in relation to playerMissile mean that %this, will always refer to $player = %this?


The above function is followed by this...

function PlayerMissile::fire(%this)
{
}

so does this %this, refer to the %this, in the first function? so %this for PlayerMissile class is then %this for player class?

Help me I am confused.






:){}{{{


About the author

My thanks to Garage Games and the Garage Games Community combined with owned determination I got one game up, Temple Racer and I am looking to build more interesting, fun games for the mass market of the iOS app store.


#1
02/20/2010 (7:37 pm)

Function parameters are local to each function, so %this here simply refers to the first parameter each of the function receives (which usually is implicitly set with the <obj>.<method> syntax). player=%this stores a copy of the parameter in the "player" field of the missile sprite in order to be able to identify the PlayerShip the missile came from.
#2
02/20/2010 (7:41 pm)
I understand that "%this" is a parameter passed into each function. My confusion comes in that when the new staticSprite is called, with in this new sprite...

player = %this


why have this?


#3
02/20/2010 (7:46 pm)
Quote:player=%this stores a copy of the parameter in the "player" field of the missile sprite in order to be able to identify the PlayerShip the missile came from.
#4
02/20/2010 (7:51 pm)
so it stores a "copy" of the parameter in the "player field of the missile sprite" in order to be able to identify the playerShip.


ok, but what is a "copy" of the parameter?
(sorry if that sounds dumb)


and what is a "player field of the missile sprite"?



thanks!
#5
02/20/2010 (8:03 pm)

Variables hold values. Values can be integers, floats, or strings. Assigning one variable to another copies the value of that variable to the other variable.

%a = 1;
%b = %a; // %b is now 1

Objects as data structures are basically collections of variables (called fields or properties in this case) that can be passed around as values themselves (identified by numeric IDs). In TorqueScript, the set of variables (=fields) an object holds can be arbitrarily extended.

So "assigning %this to the player field of the PlayerShip object" basically translates to storing a copy of the current value of the variable %this in a field (think variable) on the PlayerShip object.

Again, I strongly suggest reading an introductory text on programming.
#6
02/20/2010 (8:06 pm)
hmm ok,
i will brush up on my terminology as i believe i have the concepts down pat, its just when i hear certain terms used, and other times, it is, for me, just linking the lines or wires so to speak.

ie, many classes, objects etc need to talk to one another, getting the order of things to happen properly etc.

thanks.