Game Development Community

.getDataBlock usage.

by Luke Griffin · in Torque 3D Professional · 05/01/2011 (5:15 am) · 3 replies

Hi.

I'm trying to get text to appear in a menu system that changes based on something that you click on. I thought that I might save the text in a datablock and then load the fields when a certain icon is clicked. Problem I am facing is that all the examples of .getDatablock that I can find usually refer to items or characters in the game world and usually start with a variable such as %obj.getDatablock. I would like a way to specifiy exactly what datablock to load rather then get that information based on whats going on in the game world but am uncertain of the usage. Ive tried doing the following:

datablock ItemData(MenuInformation1)
(
   TestLine1 = "This is a test";
)

as well as:

datablock GameBaseData(MenuInformation1)
(
   TestLine1 = "This is a test";
)

and then when I click on the button i have:

function testbutton::onMouseDown()
{
   %datablock = MenuInformation1.getDataBlock();
   %mytestline = %datablock.TestLine1;
   testTextLine.setText(%mytestline);
}

Either it doesnt do anything or I get the error:

Unable to find object: 'MenuInformation1' attempting to call function 'getDataBlock'

Am I doing something stupid or are datablocks simply not setup to work in this way? Any help would be great.

#1
05/01/2011 (7:18 am)
I think you're suppose to call the "getDataBlock" method on an instance of a datablock, not the datablock itself. I'm not really advanced in scrpting, however, it might be worth looking at scriptObjects to achieve what you're trying to do.
Here's an example from the scripting reference guide :

new ScriptObject(Game)
{
class = "DeathMatchGame";
superClass = GameCore;
genre = "Action FPS"; // Note the new, non-Torque variable
};

Then just use

Game.genre
to get the value you're looking for.
#2
05/01/2011 (7:20 am)
You call getDataBlock() on a datablock.
Go to console and use MenuInformation1.dump() to get a dump.
#3
05/01/2011 (8:18 am)
Spot on! works perfectly thanks! I just changed it to:

new ScriptObject(MenuInformation1)
{
   TestLine1 = "This is a test";
};

and:

function testbutton::onMouseDown()
{
   testTextLine.setText(MenuInformation1.TestLine1);
}

Thanks for the help!