Game Development Community

N00b datablock questions

by Shawn LeBlanc · in Torque Game Builder · 03/01/2007 (5:23 am) · 7 replies

I've read the tutorials, and I think I understand the gist of it, but I still have a few questions about them

1. Is it possible to make a user-defined datablock that doesn't derive from anything? If so, what would that look like?
From what I've seen the tutorials' examples derive from (what I think are) pre-defined types (ItemData, FlyingVehicleData, etc). Maybe there's a "blank" datablock that I need to derive from?

2. Where do I find information on the pre-defined datablocks? I couldn't find a list.

3. Once I assign a datablock to an object, how do I access that data? If my datablock has a variable called Foo and I assign it to a t2dSceneObject called Bar, should I be able to go %Bar.Foo? %Bar.datablock.Foo? Does that even make sense?

Thanks!
Shawn

#1
03/01/2007 (10:10 am)
1. Are we talking engine source or script here? Can you also clarify what exactly you mean by "derive from," are you talking : notation?

2. TDN has a section on T2DSceneObjectDatablock which is probably all you will ever need for TGB.

3. In the vein of your example if your object is called Bar you access the datablock property Foo by Bar.Foo but if your object is stored in a var called %Bar then you use %Bar.Foo
#2
03/01/2007 (10:48 am)
Hi Ben,

I'm talking about the script side of things. Sorry about that bit of missing context. Also, I wrote "derive from" because some examples I saw talked about datablock inheritance. I might not have completely understood what I read. From the example, I understood that declaring a new datablock required "deriving from" a predefined datablock.

As you can see, I don't quite get it yet :)

Thanks!
Shawn
#3
03/01/2007 (1:44 pm)
After reading about T2DSceneObjectDatablock, another question comes up which might clear up a few things for me: If I want to pass a datablock to a t2dSceneObject, it can only be a 2DSceneObjectDatablock? Nothing else?

[edit] I originally thought datablocks were generic structures that we could define and pass to pretty much any kind of object in script. Datablocks like T2DSceneObjectDatablock I thought they were more like datablock "templates".
#4
03/01/2007 (3:54 pm)
It's more a case of having datablocks "copy" rather than "derive" from another datablock. Did you look at the references for the different types of datablocks on this page in TDN?

Here is an example to clarify the "copy" vs. "derive" issue.
t2dSceneObjectDatablock (dbA)
{
    class = "exterminator";
    size = "4 4";
    position = "5 15"; // a member of the datablock type we're using
    insectRepellant = "100"; // a dynamic property I just made up
}

t2dSceneObjectDatablock (dbB : dbA)
{
    class = "helper";
    position = "5 10"; // a member of teh datablock type
    extraCans = "2"; // a dynamic property I just made up
}

When dbB is created you can think of it at a high level as starting out as an identical copy of dbA which then has values overridden from the formal instantiation of dbB. So dbB has a size of 4x4, is positioned at (5, 10), has 100 insectRepellant, and two extra cans. The class of dbB is "helper" and I think of this as not being "derived" from dbA because "exterminator" will not be in the call chain of dbB (which it would if it were actually "derived" from dbA in an OO sense).

Does that clear some up?
#5
03/01/2007 (7:23 pm)
That has cleared up a lot of things, thanks!

Shawn
#6
03/01/2007 (8:56 pm)
Does it make sense that if I want to assign a datablock to a dynamically created object, I have to set its "config" field? The examples I've found use "datablock" and don't mention "config" at all. Not to mention that "datablock" doesn't work.

new t2dSceneObjectDatablock(MyFirstDataBlock) 
{   
    junkvar = "helloworld";
};

$enemy = new t2dStaticSprite() 
{ 
	class = "enemyClass"; 
	scenegraph = %scenegraph;    
	imageMap="enemyImageMap";
	config="MyFirstDataBlock"; // not datablock???
};

Shawn
#7
03/01/2007 (9:44 pm)
Yes, that is correct for TGB. You must be looking at examples from TGE if you have to set "datablock" in them. TGB uses "config" and again it just copies the values into the object. So in TGE you had to use $enemy.datablock.junkvar but in TGB you just use $enemy.junkvar