Datablocks scripting question
by Entr0py · in Torque Game Engine · 08/15/2005 (1:43 pm) · 3 replies
First of all I would like to say that I have spent the last 4 days pouring through the forums, resources and TGE docs reading up on datablocks and datablock objects. I still cannot figure out how to access a datablock value from script.
I am creating a datablock and datablock object in script like this:
so when I try myObject.dump(); I see that the datablock is indeed part of myObject(although it lists it as a tagged string, so I can't really be sure).
echo(myObject.someVariable);
returns:
"%" (i.e. empty, when it should be 10)
as does
echo(myObject.myObjectData.someVariable);
Anyway my problem is that I would like to use the datablock variable "someVariable", but I cannot seem to access it. It isn't stored in myObject.someVariable, or myObject.myObjectData.someVariable so where is it?
"someVariable" would show up if i were to do "new ScriptObject(myObject : myObjectData)" but since I am already copying from "someOtherObjectNotShownHere" this is not an option.
------------------------------------------------------------------------------
To further complicate things, I might mention that all datablocks, datablock variables, datablock variable VALUES, and classes in this structure are dynamically loaded, so I cannot use persistant fields (as the field is not known until loadtime).
So it all boils down to the ability to access a datablock value from script.
I am creating a datablock and datablock object in script like this:
datablock SimDataBlock(myObjectData){
someVariable = 10;
};
new ScriptObject(myObject : someOtherObjectNotShownHere){
datablock = "myObjectData";
};so when I try myObject.dump(); I see that the datablock is indeed part of myObject(although it lists it as a tagged string, so I can't really be sure).
echo(myObject.someVariable);
returns:
"%" (i.e. empty, when it should be 10)
as does
echo(myObject.myObjectData.someVariable);
Anyway my problem is that I would like to use the datablock variable "someVariable", but I cannot seem to access it. It isn't stored in myObject.someVariable, or myObject.myObjectData.someVariable so where is it?
"someVariable" would show up if i were to do "new ScriptObject(myObject : myObjectData)" but since I am already copying from "someOtherObjectNotShownHere" this is not an option.
------------------------------------------------------------------------------
To further complicate things, I might mention that all datablocks, datablock variables, datablock variable VALUES, and classes in this structure are dynamically loaded, so I cannot use persistant fields (as the field is not known until loadtime).
So it all boils down to the ability to access a datablock value from script.
#2
I am currently working on an intro to scripting video that covers this very thing. Here is an example for you:
Lets say you have an item in your .mis mission file like this:
Then in if we look at the crossbow.cs file we find the datablock here:
In your script you can access the arrowTest object datablock info like this:
NOTE: This is just one way to create and manipulate objects in Torque, and may not be suited for your exact needs, but it at least gets you going in the right direction.
I understand the learning curve you are faced with, but let me assure you it is worth it! I have started a video series on this very subject which might help you out also.
torque.smdlabs.com/media/freeTutorials/introTScript/page1.htm
The Objects Part1 and this week Part2 may be of the most help if your not totally new to scripting.
Good luck!
B--
EDIT: originally posted the wrong link.. Oops!
08/15/2005 (10:55 pm)
@EntrOpy:I am currently working on an intro to scripting video that covers this very thing. Here is an example for you:
Lets say you have an item in your .mis mission file like this:
new Item(arrowTest) {
position = "194.34 4.61215 53.551";
rotation = "0 0 -1 42.9718";
scale = "1 1 1";
dataBlock = "CrossbowAmmo"; // here is the datablock assignment
collideable = "0";
static = "1";
rotate = "0";
receiveSunLight = "1";
shapeName = "~/data/shapes/crossbow/ammo.dts";
useCustomAmbientLighting = "0";
customAmbientLighting = "0.000000 0.000000 0.000000 1.000000";
receiveLMLighting = "1";
customAmbientSelfIllumination = "0";
useAdaptiveSelfIllumination = "0";
};Then in if we look at the crossbow.cs file we find the datablock here:
datablock ItemData(CrossbowAmmo)
{
// Mission editor category
category = "Ammo";
// Add the Ammo namespace as a parent. The ammo namespace provides
// common ammo related functions and hooks into the inventory system.
className = "Ammo";
// Basic Item properties
shapeFile = "~/data/shapes/crossbow/ammo.dts";
mass = 1;
elasticity = 0.2;
friction = 0.6;
// Dynamic properties defined by the scripts
pickUpName = "crossbow bolts";
maxInventory = 20;
myData = "hahaha"; // here is some data you want to access
};In your script you can access the arrowTest object datablock info like this:
function myFirstFunction()
{
%myObj = arrowTest;
%myObjDataBlock = %myObj.getDataBlock();
echo(%myObjDB.myData);
}NOTE: This is just one way to create and manipulate objects in Torque, and may not be suited for your exact needs, but it at least gets you going in the right direction.
I understand the learning curve you are faced with, but let me assure you it is worth it! I have started a video series on this very subject which might help you out also.
torque.smdlabs.com/media/freeTutorials/introTScript/page1.htm
The Objects Part1 and this week Part2 may be of the most help if your not totally new to scripting.
Good luck!
B--
EDIT: originally posted the wrong link.. Oops!
#3
Thanks, that is exactly what I needed to know. I suspected as much when .dump() returned with "datablock" as a tagged string.
Brandon:
Thank you for the help, the tutorials look really good. I will check them out :)
08/16/2005 (1:59 am)
Matt: Thanks, that is exactly what I needed to know. I suspected as much when .dump() returned with "datablock" as a tagged string.
Brandon:
Thank you for the help, the tutorials look really good. I will check them out :)
Associate Matt Fairfax
PopCap