Game Development Community

.owner defined

by rennie moffat · in Torque Game Builder · 09/11/2009 (3:51 pm) · 2 replies

Hi I am just looking at code trying to better understand the concept of "owner". My logic tells me that it is used in reference to something else, ex. a bullet has an owner, which is a gun. So for instance there is this code...
%projectile.setPosition(%this.owner.position);


what I am wondering is, if I am right, how does the projectile know who the owner is? I ask this knowing that in the owner's script, "gun" I call for bullet ("projectile"), but what is the purpose of putting it in? simply showing/telling the TGB that it is a slave to something else?

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
09/11/2009 (4:16 pm)
Rennie,
Hi. The code you're looking at must be part of what is called a 'behavior'.

A behavior is (usually) a small piece of code that can be 'attached' to a game object in order to give that game object some behavior, attribute, or feature.

When a behavior is 'attached' to a game object, that game object is the behavior's 'owner'.

In practice, the way this works is that the engine creates an instance of the behavior type which is 'attached' to the game object and then assigns that instance to the game object, again making the game object the 'owner' of the behavior instance.

In the script snippet you showed above, '%this' will contain the ID of the behavior instance, and '%this.owner' will contain the ID of the object that owns that instance.

I hope this clears things up for you.
#2
09/11/2009 (4:27 pm)
oh ok, so "owner" is only used in behaviors. I did not realize that. thank you.