Game Development Community

DataBlocks, Explained!

by Travis Vroman · in Torque Game Engine · 05/20/2009 (2:01 pm) · 22 replies

First off, what are datablocks?
Essentially, datablocks are an assortment of variables and their values for an object. Not all objects require a datablock, though. For example, consider a staticShape object, which for simplicity’s sake, we’ll call exampleShape. When an object is defined in script, it is scripted something like this:

new StaticShape( exampleObject )
{
};

Okay, great. Now we have an object created, but it does nothing. Nothing shows up in our world because it has no values associated with it. Let's give it some attributes via the following scripted datablock definition:

dataBlock StaticShapeData( exampleDataBlock )
{
   shapeFile = "./art/shapes/exampleShape.dts";
   scale = "2 2 2";
   allowPlayerStep = false;
};

Notice what we have defined within our new datablock. We have shapeFile, which points to the model itself. Next, we have scale, which obviously scales the mesh on x, y and z (in this case twice the original size). Finally, we have defined allowPlayerStep to false, which means we don't want to player to be able to walk on it. We can now take this datablock and plug it into our newly created object, as follows:

new StaticShape( exampleObject )
{
   dataBlock = "exampleDataBlock";
   position = "172.456 123.456 100.467";
};

Now, when we load up our scene containing our new object, the datablock is referenced, and our mesh shows up. This way, if we need five of these objects in our scene, we only need to define these variables once, in a datablock, and reuse them. Notice I also included a position value outside of the datablock. The reason for this is due to the fact that if you define the position in the datablock, every object containing a reference to this datablock will be created at the same location. There are exceptions to this, however, but more on that later.
Page«First 1 2 Next»
#21
06/28/2011 (9:52 am)
Wow Demasiado bueno este tutorial... Gracias!!!
#22
09/02/2013 (7:44 am)
Excellent, a kick in the butt to my demon of ignorance.
Page«First 1 2 Next»