Objects and Datablocks
by Demolishun · in Torque Game Engine · 09/16/2004 (9:50 pm) · 1 replies
Here is some code I have been experimenting with:
// Start Code
//
// Test Datablock
//
datablock SimDataBlock(vehicleData)
{
type = "generic";
};
datablock SimDataBlock(carData : vehicleData)
{
type = "car";
};
datablock SimDataBlock(truckData : vehicleData)
{
type = "truck";
};
new SimObject(vehicleObject)
{
datablock = "vehicleData";
};
new SimObject(carObject : vehicleObject)
{
datablock = "carData";
};
new SimObject(truckObject : vehicleObject)
{
datablock = "truckData";
};
function SimObject::ShowType(%this)
{
echo(%this);
echo(%this.type);
echo(type);
}
vehicleObject.ShowType();
carObject.ShowType();
truckObject.ShowType();
// End Code
The output of this code is as follows:
vehicleObject
type
carObject
type
truckObject
type
I ran the tree() function and noticed that instead of including the datablocks in the objects it added a variable called datablock that was set to the text corresponding to the name of the datablock provided. Is that how I am supposed to access the data? For example:
%tempblock = carObject.datablock;
echo(%tempblock.type);
Thanks,
Frank Carney
// Start Code
//
// Test Datablock
//
datablock SimDataBlock(vehicleData)
{
type = "generic";
};
datablock SimDataBlock(carData : vehicleData)
{
type = "car";
};
datablock SimDataBlock(truckData : vehicleData)
{
type = "truck";
};
new SimObject(vehicleObject)
{
datablock = "vehicleData";
};
new SimObject(carObject : vehicleObject)
{
datablock = "carData";
};
new SimObject(truckObject : vehicleObject)
{
datablock = "truckData";
};
function SimObject::ShowType(%this)
{
echo(%this);
echo(%this.type);
echo(type);
}
vehicleObject.ShowType();
carObject.ShowType();
truckObject.ShowType();
// End Code
The output of this code is as follows:
vehicleObject
type
carObject
type
truckObject
type
I ran the tree() function and noticed that instead of including the datablocks in the objects it added a variable called datablock that was set to the text corresponding to the name of the datablock provided. Is that how I am supposed to access the data? For example:
%tempblock = carObject.datablock;
echo(%tempblock.type);
Thanks,
Frank Carney
About the author
I love programming, I love programming things that go click, whirr, boom. For organized T3D Links visit: http://demolishun.com/?page_id=67
Associate Edward F. Maurina III
Roaming Gamer LLC
You could do that, or alternately, if you have the ID (handle) to an object, you can use the getDatablock() console method:
All objects derived from/initialized with a datablock (which is all GameBase children) will have a datablock field in them.
BTW, I see in your code that you are using some 'reserved' names as your datablock names:
datablock SimDataBlock(carData : vehicleData) { type = "car"; };In the above code, vehicleData happens to be a named datablock so it's not adviseable to use this name in your actual code.
You should probably take a look at the on-line docs: here
also, there is a complete list of datablocks here
I hope this helps. Also, I'll be releasing a newer version of EGTGE (see link below) soon (means watch for release notice) so you might want to grab that too.
[HOW]EdM|EGTGE