Getting %this.name when mouse clicked
by Johnathon · in Torque Game Engine · 11/25/2007 (12:00 pm) · 4 replies
I am working with TGB to create a solitaire game, and I have run into a road block with trying to get the name of each card that has been selected. I tried the following method and I receive an ID in the console
however when I try
I recieve nothing. I have assigned the to the 'Card' class and given it a name (Club2), but the console just prints a blank line. Could someone give me a little insight into how I would do this? I tried following along with the Strategy Game tutorial, however some of the calls it made (like Selections.getCount()) where custom methods and I couldn't find them anywhere.
Thanks
function Card::onMouseDown(%this, %modifier, %worldPos, %mouseClicks)
{
echo (%this);
}however when I try
function Card::onMouseDown(%this, %modifier, %worldPos, %mouseClicks)
{
echo (%this.name);
}I recieve nothing. I have assigned the to the 'Card' class and given it a name (Club2), but the console just prints a blank line. Could someone give me a little insight into how I would do this? I tried following along with the Strategy Game tutorial, however some of the calls it made (like Selections.getCount()) where custom methods and I couldn't find them anywhere.
Thanks
#2
I think to problem is in the t2DSceneGraph.PickPoint(%worldPos) call. If I echo the %objList in the console it is empty. I have tried t2dScene.PickPoint (as mentioned in the tutorial) but it still prints blankies to the console. Within the TGB I have created a dynamic field on my object called isSelectable and set it to true, so in theory it should be printing the name of the object to the console shouldn't it?
11/25/2007 (12:37 pm)
Well, I have tried using the tutorial I found and I still receive no output to the console.function sceneWindow2D::onMouseDown( %this, %mod, %worldPos, %mouseClicks )
{
if($debugMsg::mouse::callBacks)
echo("Mouse Down");
//lets get a list of all the objects at the clicked point in the t2dScene
%objList = t2dSceneGraph.pickPoint(%worldPos);
//lets get a count of how many objects in the list
%objCount = getWordCount(%objList);
//we will start looping through the list
for(%i=0;%i<%objCount;%i++)
{
//grabing the entry corresponding to the loop
%obj = getWord(%objList, %i);
//if we find an object in the list that "isSelectable = true"
if(%obj.isSelectable)
{
//we toggle a value so we know we found an object that "isSelectable"
%selected = true;
//we kick out of the loop
%i = %objCount;
}
}
//if we found an "isSelectable" object
if(%selected)
{
//we then store that object as the selectedObj
%this.selectedObj = %obj;
if($debugMsg::mouse::selection)
echo("You have selected:" SPC %obj SPC "with the name:" SPC %obj.objectName);
}
}I think to problem is in the t2DSceneGraph.PickPoint(%worldPos) call. If I echo the %objList in the console it is empty. I have tried t2dScene.PickPoint (as mentioned in the tutorial) but it still prints blankies to the console. Within the TGB I have created a dynamic field on my object called isSelectable and set it to true, so in theory it should be printing the name of the object to the console shouldn't it?
#3
11/26/2007 (7:31 pm)
Bump! Anyone have any suggestions?
#4
11/27/2007 (5:34 pm)
I just realized I posted this in the wrong forum. I'm an idiot lol
Torque Owner Johnathon
tdn.garagegames.com/wiki/Torque_2D/Getting_Started/ObjectSelection1Tutorial
I believe this answers my question :)