.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:
as well as:
and then when I click on the button i have:
Either it doesnt do anything or I get the error:
Am I doing something stupid or are datablocks simply not setup to work in this way? Any help would be great.
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.
#2
Go to console and use MenuInformation1.dump() to get a dump.
05/01/2011 (7:20 am)
You call getDataBlock() on a datablock.Go to console and use MenuInformation1.dump() to get a dump.
#3
and:
Thanks for the help!
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!
Torque 3D Owner Lunacy
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
to get the value you're looking for.