Creating new variables for datablocks via script
by Zach Broderick · in Torque Game Engine · 11/23/2007 (12:34 am) · 4 replies
I found this tutorial on creating new variables via C++ source code.
Problem is I have created a new datablock for an object off of StaticShapeData, and I need a new variable for it.
This variable really isn't useful for anything other then this single object and I would hate to create it by adding it to the source code and subsequently EVERY object part of StaticShapeData.
How would I go about creating a new variable for this object and this object alone?
Problem is I have created a new datablock for an object off of StaticShapeData, and I need a new variable for it.
This variable really isn't useful for anything other then this single object and I would hate to create it by adding it to the source code and subsequently EVERY object part of StaticShapeData.
How would I go about creating a new variable for this object and this object alone?
#2
11/23/2007 (2:26 pm)
A more accessible example is the CheckPoint system in the Racing demo that comes with TGE. The checkpoints are objects with special fields for different object instances using the datablock.
#3
These are the easiest way to add a field to an object from script.
simply go "%obj.myField = whatever;".
A search through TDN will turn up a few words about them.
the thing to watch out for is whether you want the variable on the client side, the server side, or both.
11/23/2007 (2:56 pm)
Zach, you might want to look up "dynamic fields" as well.These are the easiest way to add a field to an object from script.
simply go "%obj.myField = whatever;".
A search through TDN will turn up a few words about them.
the thing to watch out for is whether you want the variable on the client side, the server side, or both.
#4
I was making it much harder then It needed to be.
In my code I was using what you had said Orion %obj.myfield and getting nothing back. What I needed to use was %this.myfield.
I just assumed I was doing something wrong as far as declaring my variable was concerned.
Then I went so far as to entirely forget about Dynamic Fields...which I had actually read about in Edwards Torque Book.
Orion again! (if you don't recall you just helped me in the math section with the buzzsaw physics)
You seem to be a rather helpful fellow.
11/28/2007 (1:18 am)
Haha oh wow. I feel dumb now!I was making it much harder then It needed to be.
In my code I was using what you had said Orion %obj.myfield and getting nothing back. What I needed to use was %this.myfield.
I just assumed I was doing something wrong as far as declaring my variable was concerned.
Then I went so far as to entirely forget about Dynamic Fields...which I had actually read about in Edwards Torque Book.
Orion again! (if you don't recall you just helped me in the math section with the buzzsaw physics)
You seem to be a rather helpful fellow.
Torque 3D Owner Matthew Jessick
There is only one instance of a StaticShapeData datablock. The purpose of a datablock is to hold all the stuff that doesn't change for a particular class of objects. If the value should be different for different object instances, then it shouldn't be in the datablock used by that set of objects.
new StaticShape(actionTarget_target_S5) { canSaveDynamicFields = "1"; position = "-17.0 202.0 15.05"; rotation = "0 0 1 80"; scale = "1 1 1"; dataBlock = "ActionTarget4Data"; receiveSunLight = "1"; receiveLMLighting = "1"; useAdaptiveSelfIllumination = "0"; useCustomAmbientLighting = "0"; customAmbientSelfIllumination = "0"; customAmbientLighting = "0 0 0 1"; useLightingOcclusion = "1"; myNewVariable = 4; };Above is one of my object intances that uses the ActionTarget4Data datablock. I can add a variable for just this object instance. Since this is a "target", perhaps myNewVariable is a score to be gained if it is hit. When a projectile hits it, I can check the struck object for the myNewVariable field's score value.
Note that how you do what you asked about in general, depends on specifically how you intend to use the data. Here, I don't have to use the new variable inside any shapebase datablock methods, for example. Also, as a "dynamic field", it only exists on the server.