Game Development Community

Problems with Creating Shapes

by Kiyaku · in Torque Game Engine Advanced · 10/23/2007 (12:04 am) · 2 replies

Hi there,

i'm new to TGEA, i just used TGB before.

I tried to create custom shapes to learn programing with TGEA but i somehow can't get it work. What i did is following:

1) I Created a cube as .dts and saved it in "~/data/shapes/DTSTest/Detailmap.dts"
2) Loaded the cube as StaticShape to see if it's alright - It is
3) Create a new block.cs file in "~/server/scripts/block.cs" with following code:

%myBlockie = datablock blockie() {
   category = "OwnStuff"; // also tried with "Misc"
   shapeFile = "~/data/shapes/DTSTest/Detailmap.dts";
   mass = 50;
};

%obj = new Block1()
{
  datablock = %myBlockie;
};

This might not be the best way, but the TDN said it works anyway. I also tried different things.

4) including the block.cs file in the game.cs file (which loads the other Shapes too)
5) Open my mission, press F4 and check if the Shape is listed now - it's not

I don't see the shape, no matter what i do. Did i miss anything?


Thanks in (TGE) advance! :)

#1
10/23/2007 (3:12 pm)
Just a little off on the syntax there Kiyaku. You've got the name of the datablock in the place where the datablock type should go. Also, if you just want to be able to place your custom object through the mission editor then you don't need your second part there, as that code is actually creating a new instance of your object. This is probably what you were going for:
datablock StaticShapeData(blockie) {
   category = "OwnStuff"; // also tried with "Misc"
   shapeFile = "~/data/shapes/DTSTest/Detailmap.dts";
   mass = 50;
};

function blockie::Create(%data) {
   %obj = new StaticShape() {
        dataBlock = %data;
   };
   return %obj;
}

Now, this code will implement your object as a StaticShape, which is different from what you did before, wich was place it as a TSStatic, the names are very similar (many get confused) but the key difference is that TSStatic doesn't use a datablock, but a StaticShape does. You could also replace StaticShapeData in the code above with ItemData and it will work just as well, as far as being able to put it in the world anyway.

Now, a word on the Create function, this is not strictly necessary for every object. I believe the "stock" scripts that come with Torque implement the Create function for all StaticShapeData datablocks for you, so you don't need to write one each time you create a new datablock. The only time you would need/want to do this is when you want something particularly special to happen when an instance of that datablock is created. However, considering you're just getting a handle on the basics, I wouldn't worry about this at the moment.

PS Could you post a link to the TDN article that gave you that information? It sounds like it needs to be clarified some.
#2
10/23/2007 (10:47 pm)
Hi Mark,
thanks a lot for your help, it works perfect and thanks for a deeper explanation :)

The TDN article can be found here: TDN Datablocks