Game Development Community

How do I "getSelectedObject()"?

by Nicolai Dutka · in Torque Game Engine · 09/08/2007 (1:29 pm) · 6 replies

I followed this guide for getting selectable objects and click-drag camera controls:
www.garagegames.com/index.php?sec=mg&mod=resource&page=view&qid=11152

The problem is, I don't know how to "do stuff" to the selected object such as make it playThread or MoveToObject. I don't know how to "get" the object I have selected.

#1
09/08/2007 (7:48 pm)
Ok, after messing with this ALL day, all I had to do for this to work with AI Players:

Open aiPlayers.cs (found in my server/scripts/ folder).

Add to the end:

function AIPlayer::onUse()
{
 echo("THIS WORKS!!");
}

This is AWESOME, however, it does not work so easily with static meshes. Back to digging!
#2
09/09/2007 (12:53 pm)
Also, instead of calling OnUse, you can simply do either %this.getSelectedObject() or %player.getSelectedObject(). It will return the object and you can work with it from there.
#3
09/09/2007 (12:56 pm)
Are you sure? I have tried using "getSelectedObject()" MANY times in MANY places and it keeps saying "unknown command".
#4
09/11/2007 (7:36 am)
Are you calling the getSelectedObject() alone, or as follows:

function serverCmdBap(%client)
{
   %player = %client.player;
   %target = %client.getSelectedObj();

 <snipped irrelevant script>
}

That's what I use, and it works just fine. If it still errors when you do that, maybe double-check that the function is exposed to script?
#5
09/11/2007 (5:18 pm)
I tried both. Can't get either to do anything.

I did come up with my own way of selecting things tho. Since this is an RPG and I am using the FPS as my base, I gave the characters "invisible guns" that shoot invisible bullets with a mere 6 foot range. If they hit something that I previously marked "canUse", then it uses that object. :D
#6
09/13/2007 (12:24 pm)
Clever =)