Acquiring an object's handle
by Itay Hauptman · in Torque Game Engine · 07/27/2006 (12:11 pm) · 8 replies
This is probably a stupid question, but how can I receive a handle to a specific object in the world, if I only know it's name?
I'm asking because some scripts require referencing objects you don't have handles to, so it's quite important.
Of course, the question is only relevant if I didn't create the object via script (since then I would already have its handle)
Any help would be appreciated!
I'm asking because some scripts require referencing objects you don't have handles to, so it's quite important.
Of course, the question is only relevant if I didn't create the object via script (since then I would already have its handle)
Any help would be appreciated!
About the author
#2
07/27/2006 (1:13 pm)
Have you tried getID()?
#3
@Surge -- the number doesn't help, since I need to get the ID -numbers may vary from time to time...
@Stefan - how do I use getID() ? is it an object's method? Not to be too pessimistic, but if so, it won't help, since I need the object to activate it...
07/28/2006 (1:56 am)
Thank you for your rapid responses.@Surge -- the number doesn't help, since I need to get the ID -numbers may vary from time to time...
@Stefan - how do I use getID() ? is it an object's method? Not to be too pessimistic, but if so, it won't help, since I need the object to activate it...
#4
Just write the object's name (after you assign a name to it, of course), and there you have it... You dont need to "get" it... Sorry =)
Still, objects with no name are more difficult to handle
07/28/2006 (2:01 am)
Actually, the solution is much more simple that I thought:Just write the object's name (after you assign a name to it, of course), and there you have it... You dont need to "get" it... Sorry =)
Still, objects with no name are more difficult to handle
#5
07/29/2006 (6:19 pm)
Be sure to give your objects unique names, because two objects with the same name are still allowed in torque script.
#6
However, how do I acquire, for example, the client's handle via script? (of course, assuming I'm not inside a function receiving it as a param...)
What I tried to do is write that value in a gloval var, from inside a function who receives the client's handle as a parameter, and then use that var from another function.
Is this the only way?
07/30/2006 (9:14 am)
Thanx, I'll try 2 keep that in mind =)However, how do I acquire, for example, the client's handle via script? (of course, assuming I'm not inside a function receiving it as a param...)
What I tried to do is write that value in a gloval var, from inside a function who receives the client's handle as a parameter, and then use that var from another function.
Is this the only way?
#7
E.g. this function you'll find in weapon.cs
%obj is the client.
Some other ways to get the client.
Never use a global variable to obtain the client!
07/30/2006 (9:28 am)
There's a few different ways you can do it pending on where you do it from. Some functions already have a reference to the client, as you mention.E.g. this function you'll find in weapon.cs
function Weapon::onInventory(%this,%obj,%amount)
{
// Weapon inventory has changed, make sure there are no weapons
// of this type mounted if there are none left in inventory.
if (!%amount && (%slot = %obj.getMountSlot(%this.image)) != -1)
%obj.unmountImage(%slot);
}%obj is the client.
Some other ways to get the client.
%client = ClientGroup.getObject(%i);
%client.getControlObject();
Never use a global variable to obtain the client!
#8
07/30/2006 (11:49 pm)
Thanx Tim. I'm gonna use this...
Torque Owner Surge
MDNAMEDIA
it is issued a numer like 1508. That number can be used to trigger a function of the item.
I know you want to know about name, thats all I have to offer.