Torque datablock equivalent?

BlitzMax Forums/BlitzMax Beginners Area/Torque datablock equivalent?

amaranth(Posted 2008) [#1]
I've just made the switch from Torque to BlitzMax, and I'm trying to familiarize myself with the new language...

In Torque, there is a thing called a datablock that you can use to put things into groups (classes?). I'm trying to figure out how to recreate my datablocks in BlitzMax.

For example, here are two of my Torque datablocks. The second one, "Grain" belongs to the first one, "Item":

//Item
datablock t2dSceneObjectDatablock(ItemDatablock)
{
Class = "Item";
Layer = "18";
UseMouseEvents = "1";
Size = "5 5";
};


//Grain
datablock t2dSceneObjectDatablock(i0Datablock:ItemDatablock)
{
//Grain
type = "0";
attack = "0";
price = "2";
};

Any help would be much appreciated!


ImaginaryHuman(Posted 2008) [#2]
Type Item
Field Class:String="Item"
Field Layer:Int=18
Field UseMouseEvents:Int=1
Field Size:Int=5
End Type

Local MyItem:Item = New Item
Item.Class="Item"
Item.Layer=24
Item.UseMouseEvents=0
Item.Size=11


amaranth(Posted 2008) [#3]
Great! I'm still not sure how I would create the Grain datablock. I would have it inherit the default values assigned to the Item datablock. Maybe the types would look like this:

Type Item
Field Class:String="Item"
Field Layer:Int=18
Field UseMouseEvents:Int=1
Field Size:Int=5
End Type

Type Grain:Item
Field ItemType:Int=0
Field Attack:Int=0
Field Price:Int=2
End Type

Local Grain = New Item


Dreamora(Posted 2008) [#4]
Hi Amaranth
Nice to see you over here :)


What you are looking for does not exist in that way in BM.
There is nothing that defines an "arbitary" object like a sprite or the like as BM only has a 2D through 3D based drawing system as a module to its programming and no 2d engine on top of it like TGB.
Nor does most of the other things you are used to exist unless you implement it in your own 2D engine.

The only thing that is even slightly similar to Datablocks are Types.
To replicate the behavior of your part above, you would have:

' Item
Type TItemDatablock

 field Class:String = "Item"
 field Layer:int = 18
 field UseMouseEvents:int = true
 field Size:float[] = [5 5]
end type


' Grain
type Ti0Datablock extends TItemDatablock

 field type:int = 0
 field attack:int = 0
 field price:float = 2
end type

Local Grain = Ti0Datablock  


If you want the datablock based approach with "dynamic classes" this will be a fair amount of work. There is no such mechanism or system available.
Above shows you thought how to work with the classes directly.
You can still create Template Classes (like the datablocks in TGB) and implement functionality into them ( methods ).

What you do in BM is the same what Torque does on the C++ side ...

PS: How did your teams last game work out? :)


amaranth(Posted 2008) [#5]
Ah drats, I was worried about that. No matter, I'll re-learn... I've been working my way down the coding tree backwards.

The last game is doing great! I'm ready to move on and try something new. Cartman suggested Blitz. So far, I've really enjoyed learning how to work with it. I'll probably have a flood of questions in the next couple of weeks as I get off the ground. Luckily, I'm starting with Grey Alien's Framework, so that should help a lot.

:D


Dreamora(Posted 2008) [#6]
Well that is right, targetting getting a game ready in less time, Grey Alien's Framework is actually of a lot of help :)

I'm sure you will enjoy learning it, thought you first will have to get "unused" to some of the stuff you learned in Torque as there are things that can not be replicated unless you implement an own scripting backend (MicroC from Binary Phoenix might be the simplest solution or BriskVM 2)