Game Development Community

Inheritance or Datablocks?

by Diego Santos Leao - GameBlox Studio · in Torque Game Builder · 08/26/2007 (11:31 am) · 5 replies

I'm a little confused... In TDN there is an article ( http://tdn.garagegames.com/wiki/TorqueScript/Datablocks ) explaining how to use datablocks, but the problem used as example on the article is generally solved with inheritance...

You need to represent in code three kinds of planes, and that is normally done with the creation of a "plane" class with three children: "F14", "F117", "Mig29". But in the example a single "plane" class is created and, to differentiate each kind of plane, a reference to a different datablock is used!

Ok, I understand the network issues that datablocks solves, but I want to use them without breaking object orientation. Is this possible?

How do I do this in this example?

PS: I'm having trouble understanding how OO is used in TorqueScript... is there a specific article about this? Is there support for encapsulation (private/protected/public keywords)?

#1
08/27/2007 (10:19 am)
You can derive datablocks from one another, but datablocks are only used for assigning data. But you can also specify a class and a superclass for your game objects and define functions for that class all in script.

There is no concept of public / private etc.

Heres another similar thread.

http://www.garagegames.com/mg/forums/result.thread.php?qt=9109
#2
08/27/2007 (12:45 pm)
Also, in script, you're limited to two levels of inheritance - for instance: t2dStaticSprite -> Vehicle -> Plane, but not t2dStaticSprite -> Vehicle -> Plane -> F14. Datablocks can circumvent this to some extent.
#3
08/27/2007 (5:34 pm)
#James

I read more about tgb network and it seams that in TGB there is no sincronizing between client and server objects, so I'm assuming that datablocks play a very smaller part in TGB than in TGE...

PS: I can't access that thread because I don't own TGE...

#Kalle

Thanks, that's a great limitation I didn't knew of... I'll remember that :)

--

Then... can I say that in TGB datablocks are just "blocks of constant values" (that can be used as some sort of type definition when needed)? (and do nothing about networking eficiency?)
#4
08/28/2007 (8:40 am)
Yes, in TGB datablocks are also refered to as ConfigDatablocks because they serve no networking purpose like their TGE datablock siblings. They are only for initializing objects. A config datablock will set any object fields specified in the datablock when it is assigned, size, position, bitmap, behaviors, etc..

Eg. (you might already know this) In the editor you can drag an object into your level then select it, go to the edit tab, then the scripting dropdown and you will see a popupmenu labeled config datablock, there you will find any datablocks you have defined in your game/gamescripts/datablock.cs file. You can also assign datablocks to objects in script.

For example imagine a coin pickup item. You could create one in the editor setting all its field just right, assigning all its behaviors if you are using them, then save the level, then in torsion or your script editor open your level file, cut out the definition of that object, rename it as a config datablock and save it in your datablocks.cs file. Now you have the ability to replicate that object, and any changes to the datablock definition will affect all copies (the next time you run, not real time). Any object that needs to be replicated like respawning a player, enemies, projectiles, etc. probably should have and be defined by its own config datablock.

At least this is how I use config datablocks. A newer way to do this is with the template behavior and .clone() which I believe is covered in some of the 1.5 tutorials, in which case you might not use config datablocks at all...
#5
08/28/2007 (2:24 pm)
Yay! precious information again :) thanks James, now I understand TGB datablocks much better!
I'll intend to use them just as you described (to define and replicate objects that are, in essence, just clones)

I don't want to mix behaviors with all I'm learning yet... but when I do you'll immediately notice, as new threads will appear here =)