Game Development Community

Extending the Getting Started tutorial

by Matt Johnson · in Torque Game Engine · 02/02/2007 (6:02 am) · 11 replies

Greetings!

I have just completed the Getting Started tutorial that ships with Torque 1.5. Per the suggestion on TDN, I am going to add a couple of features to this game... this raised a few beginner questions:

1. If I want to make a blue and yellow logo to go with the red one that is included, will I have to model these objects and export them with new texture maps, or is there a way to dynamically switch out texture maps on models in Torque.

2. If I understand DataBlocks correctly, They are like a class associated with each instance of a particular object? So what is the best approach to add new properties to each logo while retaining the basic structure of the logoItem Datablock? In short... I want to assign 2 points for the blue logo and 5 points for the yellow logo.

Any direction would be appreciated.

Matt

#1
02/02/2007 (6:29 am)
SetSkinName( skinName )
getSkinName()

tdn.garagegames.com/wiki/Torque_Console_Objects_10
#2
02/02/2007 (6:56 am)
@mb

After experimenting with the Torque logos that came with the Tutorial, my conclusion is that they were not set up to support the SetSkinName method. When I input "echo(1433.getSkinName());" in the console... it just returns a blank line.

Anyways, thanks for the link, I will look into setting up my own model that supports reskinning.
#3
02/02/2007 (12:29 pm)
Did some searching today and found some information about exporting .dts from 3DS Max. I basically assigned a .png texture to a simple model of a box (texture file was named "base.box.png"). I'm guessing when the .dts is loaded the "base" is a trigger that tells the engine that other skins are available (in the same directory as the shape) for reskinning.

I created "blue.box.png" and "yellow.box.png" also and fired up Torque. Worked like a charm, a simple call of "%obj.setSkinName("blue");" changed the texture to the blue file.

Now... to assign a new skin to one of the boxes when the game loads and give that instance a property that indicates it's point value... this will probably take more reading :).
#4
02/06/2007 (6:39 am)
Hi Matt. It is something I was thinking at the beginning but never done...
Anyway I think I would have done simply in this way...
-create 3 duplicates of the folder 3dtorquelogo
- rename them something like logo1, logo2, logo5
- edited the texture in each folder giving them bluecolor, yellowcolor without renaming them
- rename the shape files to logo1.dts, logo2.dts, logo5.dts
- edit the logoitem.cs file in the server folder adding to it datablocks for the new shapes of the logo you have

something like this...

datablock StaticShapeData(Logo1)
{
category = "Items";
shapeFile = "~/data/shapes/logo1/logo1.dts";
};

datablock StaticShapeData(Logo2)
{
category = "Items";
shapeFile = "~/data/shapes/logo2/logo2.dts";
};

datablock StaticShapeData(Logo5)
{
category = "Items";
shapeFile = "~/data/shapes/logo5/logo5.dts";
};

at the bottom create a on collision function for each of the logoshape and specify in the functions how many points to add to the score.

Eventually would be possible in each of the logo datablocks give them a property where you specify the points to be assigned for this shape to the player score and specify in the on collision functions to read this property and use the value to increase the score.

Anyway not tried, maybe i forgot something ;P

Then modify the
#5
02/06/2007 (7:17 am)
@JoZ
Thanks for the response! This approach was my first thought, but I am reading the GPGT Chapter 4 while I'm doing this... and I think there may be a more streamlined solution.

I would like to have it so when I add the shape in the editor, the program will assign the appropriate skin and %pointValue to the instance. To the best of my understanding so far... this would require me to create 3 dataBlocks each with a unique %pointValue and %skinColor field. I also found that a "namespace" can be inserted in the calling sequence. Soooo I tried the following....

datablock StaticShapeData(Box)
{
newField1 = "Test1";
newField2 = Test2;
};

datablock StaticShapeData(RedBox : Box)
{
className = "Box";
category = "Items";
shapeFile = "~/data/shapes/boxes/simpleshape.dts";
colorVal = "red";
points = 1;
};

datablock StaticShapeData(BlueBox : Box)
{
className = "Box";
category = "Items";
shapeFile = "~/data/shapes/boxes/simpleshape.dts";
colorVal = "blue";
points = 5;
};

function Box::onAdd(%DB, %obj)
{
%obj.setSkinName(colorVal);
}

function Box::onCollision(%this, %obj, %col)
{
if(%col.getClassName() $= "Player")
{
%client = %col.client;
%client.score = %client.score + %obj.points;
commandToClient(%client, 'SetScoreCounter', %client.score);

%obj.delete();
%logoCount = logos.getCount();
if(%logoCount > 0)
return;

// otherwise display victory screen
commandToClient(%client, 'ShowVictory', %client.score);
}
}

This isn't working... and by looking at the code, it doesn't make any sense to me how the parent object (Box) would have any knowledge of the properties of RedBox or BlueBox when ::onAdd is called. Is there something I'm missing if I want just one function to manage the reskining and one function to manage the point assignment for all "box" children in the game?

Thanks, Matt
#6
02/06/2007 (8:52 am)
Matt I've tried and found that

%client.score = %client.score + %obj.points;

doesn't work, but work instead in this way...

%client.score = %client.score + %this.points;

since it seems that it doesn' read the points property from the objects but only from datablock...
Me also I was thinking that the objects would take the "points" from their parent datablock but it seems it's not in this way...

About the texture I've not tried a solution since if I remember well I've read time before that a lot of people had a lot of problems in changing textures on the fly and unfortunately I have no time to struggle with this topic since I don't need it for the moment. So I've done as said before and, also if it's not the most correct way, it works.


I now come back to struggle with 3DWS hoping Constructor will come very soon...
Maybe would be better to try another BSP editor ehehehhe...

Bye for the moment...
JoZ
#7
02/06/2007 (11:17 am)
You could try doing it like this:

datablock StaticShapeData(Box)
{
shapeFile = "~/data/shapes/boxes/simpleshape.dts";
};

datablock StaticShapeData(RedBox : Box)
{
points = 1;
};

datablock StaticShapeData(BlueBox : Box)
{
points = 5;
};

function RedBox::onAdd(%DB, %obj)
{
%obj.setSkinName("red");
}

function BlueBox::onAdd(%DB, %obj)
{
%obj.setSkinName("blue");
}
#8
02/06/2007 (2:36 pm)
@mb: ya, there may not be a way around the redundency of having the same function for each unique datablock namespace... but just wanted to see if I could do it for learning's sake. So in this setup I would need to create two more on collision functions... one for RedBox and one for BlueBox, correct?

Thanks
#9
02/06/2007 (5:38 pm)
Ok... i got it so the appropriate color skin is applied to the box when it is added in the editor using a dynamic field from each of the datablocks. This also uses one function to handle incrementing the score properly on collision based on another dynamic field from the datablocks:

function ItemData::Create(%data)
{
%obj = new Item() {
dataBlock = %data;
static = true;
rotate = true;
};
return %obj;
}

function ItemData::onAdd(%this, %obj)
{
%obj.setSkinName(%this.skin);
}

function ItemData::onCollision(%this, %obj, %col)
{
if(%col.getClassName() $= "Player")
{
%client = %col.client;
%client.score = %client.score + %this.value;
echo(%this.value);
commandToClient(%client, 'SetScoreCounter', %client.score);

%obj.delete();
%boxCount = boxes.getCount();
if(%boxCount > 0)
return;

// otherwise display victory screen
commandToClient(%client, 'ShowVictory', %client.score);
}
}

// datablock definitions
datablock ItemData(RedBox)
{
category = "Items";
// basic item properties
shapeFile = "~/data/shapes/boxes/simpleshape.dts";
// dynamic properties defined by the scripts
value = 1;
skin = "base";
};

datablock ItemData(BlueBox)
{
category = "Items";
// basic item properties
shapeFile = "~/data/shapes/boxes/simpleshape.dts";
// dynamic properties defined by the scripts
value = 2;
skin = "blue";
};

datablock ItemData(YellowBox)
{
category = "Items";
// basic item properties
shapeFile = "~/data/shapes/boxes/simpleshape.dts";
// dynamic properties defined by the scripts
value = 5;
skin = "yellow";
};
#10
02/07/2007 (1:25 pm)
Ehi Matt, well done, as said I'm not to much confident with script and more focused on content creation...
But I'm pretty interested in your script, can I ask you to comment it a bit?
Obviously, if and when you have time...

Tnx ;)
Bye!
#11
02/08/2007 (7:22 am)
Absolutely... I should have some time later this evening, it would probably help solidify the concept to me if I comment it out anyway.

MJ