Game Development Community

Displaying objects in TGB during Runtime

by Johnathon · in Torque Game Engine · 11/30/2007 (1:25 pm) · 17 replies

I am currently at a lose, I have imported all of the image maps into my TGB project, but have not added anything to my scene other than a background with a layer of 20. I then progmatically add objects into my scene, assigning the imagemaps, and trying to make them visible on layer 0, but nothing shows up. Does anyone know what I am doing wrong?

// ============================================================
// Project            :  GoFish
// File               :  .\game\gameScripts\Table.cs
// Copyright          :  
// Author             :  Johnathon
// Created on         :  Wednesday, November 28, 2007 8:14 PM
//
// Editor             :  Codeweaver v. 1.2.2685.32755
//
// Description        :  
//                    :  
//                    :  
// ============================================================

$Table::Slot0_CardCount = 0;
$Table::Slot1_CardCount = 0;
$Table::Slot2_CardCount = 0;
$Table::SelectedCard = "null";
$Deck = new simset();
$DeckBack = "ImageMap"; //backside of the card

function CreateDeck()
{
	for (%face = 0; %face != 4; %face++)
	{
		for (%value = 1; %value != 14; %value++)
		{
			%card = new t2dSceneObject(getCardName(%face, %value))
			{
				defaultconfig = CardDataBlock;
				scenegraph = t2dScene.SceneGraph;
				cardFace = %face;
				cardValue = %value;
				imageMap = "CardBack";
				position = getSlot(0);
			};
			%card.setLayer = 1;
			$Deck.Add(%card);
		}
	}
	
	//randomize the deck
	$DeckSorter = $Deck;
	$Deck = new simset();
	while ($DeckSorter.getCount() > 0)
	{
		%card = $DeckSorter.getObject(getRandom(0, $DeckSorter.getCount() - 1));
		$Deck.add(%card);
		$DeckSorter.Remove(%card);
	}
	
	for (%value = 0; %value != $Deck.getCount(); %value++)
	{
		%card = $Deck.getObject(%value);
		echo("Card: " @ getCardName(%card.cardFace, %card.cardValue));
		%card.setVisible(true);
	}
}

function setupTable()
{
	for (%count = 0; %count != $Deck.getCount(); %count++)
	{
		%card = $Deck.getObject(%count);
		%card.Position = getSlot(0);
		%card.ImageMap = $DeckBack;
		%card.setVisible(true);
	}
}

function getImageName(%face, %value)
{
	%img = "Cards";
	
	switch$ (%face)
	{
		case "0": //Hearts
			%img = %img @ "Hearts" @ %value @ $DeckBack;
		case "1": //clubs
			%img = %img @ "Clubs" @ %value @ $DeckBack;
		case "2": //Diamonds
			%img = %img @ "Diamonds" @ %value @ $DeckBack;
		case "3": //Spades
			%img = %img @ "Spades" @ %value @ $DeckBack;
	}
}

function getCardName(%face, %value)
{
	switch$ (%face)
	{
		case "0":
			%img = "Hearts" @ %value;
		case "1":
			%img = "Clubs" @ %value;
		case "2":
			%img = "Diamonds" @ %value;
		case "3":
			%img = "Spades" @ %value;
	}
}

#1
11/30/2007 (2:13 pm)
Two possible areas to check for fast confirmation:

%card = new t2dSceneObject(getCardName(%face, %value))
			{
				defaultconfig = CardDataBlock;
				[b]scenegraph = t2dScene.SceneGraph[/b];
				cardFace = %face;
				cardValue = %value;
				imageMap = "CardBack";
				[b]position = getSlot(0);[/b]
			};

I've bolded both of the lines you should look at.

scenegraph = t2dScene.SceneGraph

You have two possible issues here:

1) are you 100% sure "t2dScene" is the proper name? If the object t2dScene does not exist, you should be getting a warning in your console saying something similar to "unable to find object".

Also (and this is probably your main issue) "t2dScene.SceneGraph" is not a defined persistent or dynamic field, and therefore TorqueScript is treating your use of it as an initialization of a new dynamic field--and the default value for any dynamic field creation assignment is ""--meaning that the value of your %card.scenegraph is being set equal to "". That guarantees you cannot display the card (it doesn't have a valid scenegraph assigned).

If t2dScene is a valid object, you should be able to simply use the line:

scenegraph = t2dScene;

If t2dScene is not a valid t2dSceneGraph object, then you will need to be a little more specific. Something on the order of figuring out the name of your scene window, and then calling XXXX.getSceneGraph() on that object, or finding the name (default, or if you changed it in the level builder, what you changed it to) and using that in place of t2dScene.

2) There is a second issue, with the line

position = getSlot(0);

used within the object creation body. Actually, it's two issues, one very subtle, and one more blatant:

A) While the TorqueScript parser will let you (it's a subtle design flaw in TorqueScript), you should not make function or method calls within the body of the new statement ( the stuff between { and }; after the keyword new). This can set the parser into an undetermined state, and have unknown (and very difficult to track) execution issues.

B) You also should not directly assign values to the "position" dynamic field of a T2D object--instead, you should use the method "SetPosition(X, Y)'). We don't see your implementation of the Script Function "getSlot(...)" so I can't give the exact syntax of how to call setPosition() for your %card, but the reference documentation and possibly some echo statements should help you figure it out :)
#2
12/01/2007 (9:19 am)
Thanks Stephen for your input. I checked in the console for any unable to find object errors and I did not have any, but I did go ahead and change my
sceneGraph = t2dScene.SceneGraph;

to read as
sceneGraph = t2dScene;

However this did not fix the problem. So then I commented out the line where I am setting the position within the new statement, and used the SetPosition() method that you spoke of, and I am still not seeing any objects on my table.

below is a screenshot of the temporary table.

i85.photobucket.com/albums/k71/Scionwest/solitaire-1.jpg
Sorry about not posting up all of the source, this post has the complete source that I have wrote thus far.

Thanks for your help!


In my game.cs file I am executing a single file that contains all of the scripts that need executing, then I am calling createDeck(); and setuptable(); both methods are located in the table.cs script

function startGame(%level)
{
	exec("./Execute.cs");
   Canvas.setContent(mainScreenGui);
   Canvas.setCursor(DefaultCursor);

   new ActionMap(moveMap);   
   moveMap.push();
   
   $enableDirectInput = true;
   activateDirectInput();
   enableJoystick();
   
   sceneWindow2D.loadLevel(%level);
   CreateDeck();
	setupTable();
}

Then in the execute.cs file I am executing the following files
exec("./datablocks.cs");
exec("./Mouse.cs");
exec("./Cards.cs");
exec("./Table.cs");

datablocks.cs
datablock t2dSceneObjectDatablock(CardDataBlock)
{   
	size = "7.00 10.000";  
	//imageMap = someValidImageMapContainingYourCardImagesPreSorted   
	cardFace = $Card::FACE_HEART;   
	cardValue = $Card::Value_Ace;
	layer = 0;
};

mouse.cs
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);
        }
}

cards.cs
//0 = Pile
//1 = Winning Slot (Very top)
//2 = Player Hand slot 0
//3 = player hand slot 1
//4 = player hand slot 2
//5 = player hand slot 3
//6 = player hand slot 4
//7 = player hand slot 5
function getSlot(%slot)
{
	switch$ (%slot)
	{
		case "0":
			%position = "-30.000 -19.000";
		case "1":
			%position = "4.000 -20.000";
		case "2":
			%position = "-26.000 -6.000";
		case "3":
			%position = "-14.000 -6.000";
		case "4":
			%position = "-2.000 -6.000";
		case "5":
			%position = "10.000 -6.000";
		case "6":
			%position = "22.000 -6.000";
		case "7":
			%position = "34.000 -6.000";
	}
	
	return %position;
	
}

//Offset to the slot the card was placed into.
//pile: offset 0 = Pile
//pile: offset 1 = over-turned cards
//winning: offset 0 = hearts
//winning: offset 1 = clubs
//winning: offset 2 = diamonds
//winning: offset 3 = spades
//hand: offset 0 = base position
//hand: offset 1 = next card placed after offset 0
function getOffset(%slot, %offset)
{
	switch$ (%slot)
	{
		//Pile
		case "0":
			if (%offset == "0") //Card Pile
				return "-30.000 -20.000";
			else if(%offset == "1") //Bottom of 3 cards drawn
				return "-22.000 -20.000";
			else if (%offset == "2") //Middle of 3 cards drawn
				return "-21.000 -20.000";
			else if (%offset == "3") //Top card of 3 cards drawn
				return "-20.000 -20.000";
		//Winnings
		case "1": 
			if (%offset == "0")//Hearts
				return "-2.000 -20.000";
			else if (%offset == "1") //Clubs
				return "10.000 -20.000";
			else if (%offset == "2") //Diamonds
				return "22.000 -20.000";
			else if (%offset == "3") //Spades
				return "34.000 -20.000";
		//Hand slot 0
		case "2":
			
	}
}

function Card::Move(%this, %slot)
{
	%this.setPosition(getSlot(%slot));
}

function Card::onMouseDown(%this, %modifier, %worldPos, %mouseClicks)
{
	echo (%this.getName());
	$Table::SelectedCard = %this.getName();
}

table.cs
$Table::SelectedCard = "null";
$Deck = new simset();
$DeckBack = "CardBack"; //backside of the card

function CreateDeck()
{
	echo("Creating standard deck");
	for (%face = 0; %face != 4; %face++)
	{
		for (%value = 1; %value != 14; %value++)
		{
			%card = new t2dSceneObject(getCardName(%face, %value))
			{
				defaultconfig = CardDataBlock;
				scenegraph = t2dScene;
				cardFace = %face;
				cardValue = %value;
				imageMap = "CardBack";
				//position = getSlot(0);
			};
			%card.setLayer = 1;
			$Deck.Add(%card);
		}
	}
	
	echo("Deck created successfully.");
	//randomize the deck
	echo("Preparing to shuffle deck.");
	$DeckSorter = $Deck;
	$Deck = new simset();
	while ($DeckSorter.getCount() > 0)
	{
		%card = $DeckSorter.getObject(getRandom(0, $DeckSorter.getCount() - 1));
		$Deck.add(%card);
		$DeckSorter.Remove(%card);
	}
	echo("Deck shuffling completed.");
}

function setupTable()
{
	echo("Setting up game table.");
	for (%count = 0; %count != $Deck.getCount(); %count++)
	{
		%card = $Deck.getObject(%count);
		%cardsetPosition(getSlot(0)); //slot 0 = pile
		%card.ImageMap = $DeckBack;
		%card.setVisible(true);
	}
	echo("Deck hand created.");
	//TODO: Move cards starting from top of deck to each needed slot.
	
	echo("Table setup completed.");
}

function getCardName(%face, %value)
{
	switch$ (%face)
	{
		case "0":
			%img = "Hearts" @ %value;
		case "1":
			%img = "Clubs" @ %value;
		case "2":
			%img = "Diamonds" @ %value;
		case "3":
			%img = "Spades" @ %value;
	}
}

Edit: Spelling corrections
#3
12/01/2007 (9:27 am)
I wanted to bring up that when I try to set move the cards into the 'pile' in table.cs->setupTable() I am using %card.setPosition, but I have a card.cs->Card::Move() method declared and when I try and use it (%card.Move()) I receive an error (actually 52 errors, one for each card due to the loop). So I reverted back to using setPosition(). Could this be part of the problem maybe?

game/gameScripts/Table.cs (63): Unknown command Move.
  Object Diamonds10(1392) Diamonds10 -> t2dSceneObject -> BehaviorComponent -> DynamicConsoleMethodComponent -> SimComponent -> SimObject

Also, this is the console ouput for code snippits provided in my previous post. I ran a console command (shown in bold) to see if the card has had it's position set after loading, and it has. it's in the correct position, so my getSlot() method is returning a proper value.
Torque Game Builder (v1.5.1) initialized...
Loading compiled script C:/Users/Johnathon/Documents/MyGames/GoFish/game/managed/datablocks.cs.
Loading compiled script C:/Users/Johnathon/Documents/MyGames/GoFish/game/managed/persistent.cs.
Loading compiled script C:/Users/Johnathon/Documents/MyGames/GoFish/game/managed/brushes.cs.
Loading compiled script C:/Users/Johnathon/Documents/MyGames/GoFish/game/gameScripts/datablocks.cs.
Loading compiled script C:/Users/Johnathon/Documents/MyGames/GoFish/game/gui/mainScreen.gui.
Loading compiled script C:/Users/Johnathon/Documents/MyGames/GoFish/game/gameScripts/game.cs.
Loading compiled script C:/Users/Johnathon/Documents/MyGames/GoFish/game/gameScripts/Execute.cs.
Loading compiled script C:/Users/Johnathon/Documents/MyGames/GoFish/game/gameScripts/datablocks.cs.
Loading compiled script C:/Users/Johnathon/Documents/MyGames/GoFish/game/gameScripts/Mouse.cs.
Loading compiled script C:/Users/Johnathon/Documents/MyGames/GoFish/game/gameScripts/Cards.cs.
Loading compiled script C:/Users/Johnathon/Documents/MyGames/GoFish/game/gameScripts/Table.cs.
Activating DirectInput...
DirectInput joystick failed to enable!
Loading compiled script C:/Users/Johnathon/Documents/MyGames/GoFish/game/data/levels/CardTable.t2d.
Creating standard deck
Deck created successfully.
Preparing to shuffle deck.
Deck shuffling completed.
Setting up game table.
Deck hand created.
Table setup completed.[b]
==>%card = $Deck.getObject(0); echo("Card Name: " @ %card.getName() @ "\nCard Position: " @ %card.getPosition());
Card Name: Diamonds11
Card Position: -30.000000 -19.000000[/b]
DirectInput deactivated.
XML::beginWrite - Failed to write to filecommon/commonConfig.xml.
saveGameConfigurationData - Failed to write to file: common/commonConfig.xml
Shutting down the OpenGL display device...
Making the GL rendering context not current...
Deleting the GL rendering context...
Releasing the device context...

Thanks again.
#4
12/01/2007 (10:48 am)
Ok, seeing a couple of inconsistencies that might point to your root errors:

--you are in some cases referring to your t2dSceneGraph as "t2dSceneGraph" :

%objList = t2dSceneGraph.pickPoint(%worldPos);

and in your card creation, you are referring to it as t2dScene :

scenegraph = t2dScene;

The second should probably be t2dSceneGraph.

Alternatively, once you properly identify the name of your t2dSceneWindow, you can call the method .getSceneGraph() on the window itself--a more consistent approach. The code in your startGame() (which, if I remember correctly, is stock code) shows:

sceneWindow2D.loadLevel(%level);

and if this is working, that implies that you can use the following technique when creating your individual cards:

function CreateDeck()
{
	echo("Creating standard deck");
       [b]%mySceneGraph = sceneWindow2D.getSceneGraph();[/b]
	for (%face = 0; %face != 4; %face++)
	{
		for (%value = 1; %value != 14; %value++)
		{
			%card = new t2dSceneObject(getCardName(%face, %value))
			{
				defaultconfig = CardDataBlock;
				[b]scenegraph = %mySceneGraph[/b];
				cardFace = %face;
				cardValue = %value;
				imageMap = "CardBack";
				//position = getSlot(0);
			};
			%card.setLayer = 1;
                        [b]// aren't we missing the setPosition call here?[/b]
			$Deck.Add(%card);
		}
	}
	
	echo("Deck created successfully.");
	//randomize the deck
	echo("Preparing to shuffle deck.");
	$DeckSorter = $Deck;
	$Deck = new simset();
	while ($DeckSorter.getCount() > 0)
	{
		%card = $DeckSorter.getObject(getRandom(0, $DeckSorter.getCount() - 1));
		$Deck.add(%card);
		$DeckSorter.Remove(%card);
	}
	echo("Deck shuffling completed.");
}

One more typo I saw visually--you've probably already corrected it, but :
function setupTable()
{
	echo("Setting up game table.");
	for (%count = 0; %count != $Deck.getCount(); %count++)
	{
		%card = $Deck.getObject(%count);
		[b]%cardsetPosition(getSlot(0)); [/b] //slot 0 = pile
		%card.ImageMap = $DeckBack;
		%card.setVisible(true);
	}
	echo("Deck hand created.");
	//TODO: Move cards starting from top of deck to each needed slot.
	
	echo("Table setup completed.");
}

You are missing the period between %card and setPosition() in this line.
#5
12/01/2007 (11:03 am)
--you are in some cases referring to your t2dSceneGraph as "t2dSceneGraph" :


%objList = t2dSceneGraph.pickPoint(%worldPos);
and in your card creation, you are referring to it as t2dScene :

scenegraph = t2dScene;
The second should probably be t2dSceneGraph.

The %objList = t2dSceneGraph.pickPoint(%worldPos); was found in a resource here at GG.

Looks like I need to do some reading so I can understand the differances between t2DSceneGraph and t2DScene.

%currentSceneGraph = SceneWindow2D.getSceneGraph();
	for (%face = 0; %face != 4; %face++)
	{
		for (%value = 1; %value != 14; %value++)
		{
			%card = new t2dSceneObject(getCardName(%face, %value))
			{
				defaultconfig = CardDataBlock;
				scenegraph = %currentSceneGraph;
				cardFace = %face;
				cardValue = %value;
				imageMap = "CardBack";
				//position = getSlot(0);
			};
			%card.setLayer = 1;
			%card.setPosition(getSlot(0));
			$Deck.Add(%card);
		}
	}
[/code

I modified my sceneGraph to use sceneWindow2D.getSceneGraph(), but when I run the game I still don't see the cards. 
[code]
%card.setLayer = 1;                        // aren't we missing the setPosition call here?			$Deck.Add(%card);
It was moved into the setupTable() method. Thanks for pointing out the type, you where right as I had already fixed that. Still no gold yet :(

Again, when I run the
==>%card = $Deck.getObject(0); echo("Card Name: " @ %card.getName() @ "\nCard Position: " @ %card.getPosition()); command in the console it outputs the correct position, it's just not getting drawn for somereason. Grr.

Thanks for the help, any more idea's?
#6
12/01/2007 (11:42 am)
Echo out the scenegraph field on the cards as well, and see what they are saying.
#7
12/01/2007 (11:44 am)
PS: If you are still stuck in the next 30/45 minutes, .zip up your project (the whole "MyGame" dir is fine) and email it off to me. I've got some time and can probably figure out the issue a lot quicker with direct debugging instead of "guided through forum posts" debugging, and save us both some time :)
#8
12/01/2007 (12:54 pm)
Sorry, just saw the posts. I'll go ahead and zip it off and send it to you.

Thanks!
#9
12/01/2007 (1:26 pm)
I tried to send you an email but it failed. I will see if I can get the file uploaded and you can just download it.
#10
12/01/2007 (1:41 pm)
You can download it from here. Just let me know when you get it so I can remove it. Thanks :D

Edit: Removed link
#11
12/01/2007 (1:59 pm)
Ok I've got it, and you'll be surprised to note that the issue is totally unrelated to what we were discussing.

In your for loops during your deck creation, you are using an improper test:

for (%face = 0; %face != 4; %face++)

Where it should be

for (%face = 0; %face < 4; %face++)

there are some other errors I'm working through, one of which is using == when you mean to be using $= (have to use $= when comparing strings), and an issue with your tilemap being on layer 0 with your cards being on layer 1, and finally the one I'm working on now where you are missing syntax for setLayer as a method instead of a field.

Will let you know when I finish it out :)
#12
12/01/2007 (2:01 pm)
Holy crap, lol. Thanks, I appreciate the help!
#13
12/01/2007 (2:15 pm)
You know, sometimes it's the simple things that get you:

function CreateDeck()
{
	echo("Creating standard deck");
	%currentSceneGraph = SceneWindow2D.getSceneGraph();
	for (%face = 0; %face < 4; %face++)
	{
		for (%value = 1; %value < 14; %value++)
		{
			%card = new [b]t2dStaticSprite[/b](getCardName(%face, %value))
			{
				defaultconfig = CardDataBlock;
				scenegraph = %currentSceneGraph;
				cardFace = %face;
				cardValue = %value;
				imageMap = "CardBack";
				//position = getSlot(0);
			};
			%card.setLayer(1);
			%card.setPosition(getSlot(0));
			$Deck.Add(%card);
		}
	}

You were creating your cards as t2dSceneObject, which in fact cannot render anything at all. They need to be either t2dStaticSprite, or t2dAnimatedSprite to have the ability to render onscreen.

Also, you've confused fields with methods (a normal confusion, don't feel bad) in your table setup:

function setupTable()
{
	echo("Setting up game table.");
	for (%count = 0; %count != $Deck.getCount(); %count++)
	{
		%card = $Deck.getObject(%count);
		%card.setPosition(getSlot(0)); //slot 0 = pile
		[b]%card.setImageMap($DeckBack);[/b] // we have to call the setImageMap() method, not change a field
		%card.setVisible(true);
	}
	echo("Deck hand created.");
	//TODO: Move cards starting from top of deck to each needed slot.
	
	echo("Table setup completed.");
}

The reason we treat them as fields when first creating an object (the new command) is because everything within the { }; block of a new statement are actually arguments sent to the new command. Once the object has been created, pretty much everything we want to do to change things on the object has to be done with methods, not direct data field changes.


Don't forget to go in to your level builder and set your tilemap to be at a layer higher than your cards (which you've determined is 1)--currently, it is set as 0, and will be "on top of" your cards.
#14
12/01/2007 (2:21 pm)
One more note: I am highly suspicious that this code won't do what you expect:

function setupTable()
{
	echo("Setting up game table.");
	[b]for (%count = 0; %count != $Deck.getCount(); %count++)[/b]
	{
		%card = $Deck.getObject(%count);
		%card.setPosition(getSlot(0)); //slot 0 = pile
		%card.setImageMap($DeckBack);
		%card.setVisible(true);
	}
	echo("Deck hand created.");
	//TODO: Move cards starting from top of deck to each needed slot.
	
	echo("Table setup completed.");
}

We're using a technique that's common to a while loop, but within a for statement, which could cause problems. I could be wrong, but it bears watching in the future.

My final recommendation : since you seem relatively new to programming (that is not an insult--one of the reasons this thread got my attention is that you are demonstrating good organization and logic skills!), I highly suggest you download Torsion and get used to working with it.

Torsion is a TorqueScript IDE (Integrated Development Environment) that is designed to work hand in hand with TorqueScript, and gives you the ability to interact with your program while it is running--set breakpoints within the code to stop execution (so you can inspect variables, watch flow, etc), and is well worth learning how to work with--will save you hours and hours of troubleshooting :)
#15
12/01/2007 (8:13 pm)
Thanks alot for taking the time to look over the code, I appreciate it! I've spent the last year messing with C# and I'm still learning. My coding practices should probably be better but I'm learning flying by the seat of my pants with C# lol.
Thanks for the explanation on methods and fields. I use them all the time in C# but didn't even think about applying it in TorqueScript. Also good to know that the new command is actually passing args. I didn't know that's how that worked.

Quote:
You were creating your cards as t2dSceneObject, which in fact cannot render anything at all. They need to be either t2dStaticSprite, or t2dAnimatedSprite to have the ability to render onscreen.
Woops, what's funny about that is I copied alot of the fields from the saved level (by adding them to the level and viewing the saved file). I never even noticed that TGB saves them out as t2dStaticSprite.

I tried out the Torsion Demo until it expired. Then I moved to NetMercs CodeWeaver and stuck with it (mainly because it was free), the only downfall is the debugging doesn't work which is a bummer. Is Torsion a much better IDE in your opinion?

So now I can see my cards being created on the table, which is fantastic! However, I forgot that I need to be able to click on them and find out what the object's name is. I was assigning this within TGB along with assigning each card to the Card class and it was working good. I was able to see my echo's into the console showing the cards name. Now that I'm doing things dynamically, I can no longer access the Card::onMouseDown method. I updated my new command to assign an internalName (assuming that's the same as the Name field within TBG) and I assigned it "Card" for the className. Now when I click on it my echo's aren't being printed to the console, so the onMouseSelected must not be getting called. Do you know what might be wrong with that? Is internalName and className the correct way to go?

%card = new t2dStaticSprite(getCardName(%face, %value))
			{
				defaultconfig = CardDataBlock;
				scenegraph = %currentSceneGraph;
				cardFace = %face;
				cardValue = %value;
				imageMap = "CardBack";
				className = "Card";
				internalName = "Back";
				useMouseEvents = true;
				slot = "0";
				offset = "0";
				//position = getSlot(0);
			};
			%card.setLayer = 1;
			%card.setPosition(getSlot(0));
			$Deck.Add(%card);
		}

You can add a card into the TGB, assign a className of "Card" and a name of "WhateverName" and you'll notice it's name gets printed to the console. However, none of the cards created with the above code echo's it's name.

Again, thanks for helping out!
#16
12/01/2007 (11:17 pm)
It's not actually "className", it's just "class", but otherwise yes.
#17
12/01/2007 (11:56 pm)
Hmm, you're right, I changed it to class and it fixed the problem, which is strange because the TorqueScript referance shows className is used to assign a class to a datablock.

Perfect, I got all the cards loaded! The only thing I haft to fix now is when I click on a card and all 52 cards call their Card::onMouseDown() method. I'm sure I will be able to get this figured out tomorrow. It's to late now :D

Thanks again for all the help!