Assigning multiple datablocks to an object?
by Drethon · in Torque Game Builder · 05/17/2009 (5:55 pm) · 5 replies
I'm trying to build an objects from components so the base object's attributes are a combination of the component attributes. It seems like datablocks would be a valid choice for the components as the attributes are static.
Unfortunately what research I've done says I can't load multiple datablocks into a single object or access one datablock from another so what would be the valid option within TGB for what I'm trying to do?
Thanks
Unfortunately what research I've done says I can't load multiple datablocks into a single object or access one datablock from another so what would be the valid option within TGB for what I'm trying to do?
Thanks
#2
If this worked with datablocks it might look like:
datablock t2SceneObjectDatablock ( Component1 )
{
attribute = 1 ;
}
datablock t2SceneObjectDatablock ( Component2 )
{
attribute = 2 ;
}
datablock t2SceneObjectDatablock ( ComponentA )
{
attribute = A ;
}
datablock t2SceneObjectDatablock ( ComponentB )
{
attribute = B ;
}
datablock t2SceneObjectDatablock ( Object )
{
ComponentNum = Component1 ;
ComponentAlpha = ComponentA ;
}
And later on changing by:
Object.ComponentNum = Component2 ;
Object.ComponentAlpha = ComponentB ;
Is there a way this can be done in script, I assume with something other than datablocks...
05/18/2009 (5:51 am)
That works for initial creation but I want to dynamically move the components around so an object can be reconstructed at any point in the game.If this worked with datablocks it might look like:
datablock t2SceneObjectDatablock ( Component1 )
{
attribute = 1 ;
}
datablock t2SceneObjectDatablock ( Component2 )
{
attribute = 2 ;
}
datablock t2SceneObjectDatablock ( ComponentA )
{
attribute = A ;
}
datablock t2SceneObjectDatablock ( ComponentB )
{
attribute = B ;
}
datablock t2SceneObjectDatablock ( Object )
{
ComponentNum = Component1 ;
ComponentAlpha = ComponentA ;
}
And later on changing by:
Object.ComponentNum = Component2 ;
Object.ComponentAlpha = ComponentB ;
Is there a way this can be done in script, I assume with something other than datablocks...
#3
05/18/2009 (6:05 am)
Or might this be a case where I'm better off dropping into the engine now?
#4
05/19/2009 (10:12 am)
I figured out a solution. By storing the internalName of a datablock in a field, I can access the data to that datablock, this way I can have multiple datablocks mix and match to make up the attributes of an object...
#5
05/19/2009 (12:25 pm)
Good solution, Drethon... the old "Composition instead of Inheritance" to the rescue ;-)
Associate Phillip O'Shea
Violent Tulip
// TestData1.MyField1 == Test1 // TestData1.MyField2 == Test2 datablock t2dSceneObjectDatablock( TestData1 ) { MyField1 = "Test1"; MyField2 = "Test2"; }; // TestData2.MyField1 == Test1 // TestData2.MyField2 == OverrideTest2 datablock t2dSceneObjectDatablock( TestData2 : TestData1 ) { MyField2 = "OverrideTest2"; };