How do you access scripted variables inserted by addField()
by Chris Garrett (CG) · in Torque Game Engine · 09/30/2003 (7:05 am) · 13 replies
How do you access scripted variables inserted by addField()? Im using an object derived off of SceneObject. Yes melvs..... :)
I have a few fields that I add in cgRenderObject::initPersistFields():
addField("Name", TypeFilename,Offset( mLineName, cgRenderObject ) );
addField("Index", TypeS32, Offset( mLineIndex, cgRenderObject ) );
addField("Texture", TypeFilename, Offset( mTextureName, cgRenderObject ) );
I have looked around in source and I have seen getDataField() used. So I tried different variations of this:
const char *strName = obj->getDataField("name", NULL);
with no success. Does anyone know how to do this??
Thanks
CG
I have a few fields that I add in cgRenderObject::initPersistFields():
addField("Name", TypeFilename,Offset( mLineName, cgRenderObject ) );
addField("Index", TypeS32, Offset( mLineIndex, cgRenderObject ) );
addField("Texture", TypeFilename, Offset( mTextureName, cgRenderObject ) );
I have looked around in source and I have seen getDataField() used. So I tried different variations of this:
const char *strName = obj->getDataField("name", NULL);
with no success. Does anyone know how to do this??
Thanks
CG
#2
09/30/2003 (8:00 am)
Or a member in script.
#3
Con::printf("Adding [%s] to scene.", obj->getDataField("MyName",NULL));
for example
CG
09/30/2003 (8:32 am)
Xavier: Yeah I understand that I can use a member mLineName from inside the class. I want to use the object in say.... SceneGraph::addObjectToScene() so I can print out what has loaded.Con::printf("Adding [%s] to scene.", obj->getDataField("MyName",NULL));
for example
CG
#4
You can also try obj->getDataBlock()->mVarName
if mVarName is public.
09/30/2003 (10:16 am)
Actually, thats exactly how you do it ;)You can also try obj->getDataBlock()->mVarName
if mVarName is public.
#5
09/30/2003 (8:06 pm)
Or you can do it the good way (tm) and add public methods to access the private mWhatever variable.
#6
10/01/2003 (6:21 am)
You should access C++ members by using C++... using the scripting system to do it just brings in unneeded complexity and the possibility for typos and such...
#7
Xavier: Yes public variable or expose thru a public method I can do...
BUT there must be a use for getDataField()? If you trace thru the code you will see what its doing and it looks like its accessing those fields you have exposed to scripting.
CG
10/01/2003 (6:30 am)
Ben: Using getDataField() is using C++. Xavier: Yes public variable or expose thru a public method I can do...
BUT there must be a use for getDataField()? If you trace thru the code you will see what its doing and it looks like its accessing those fields you have exposed to scripting.
CG
#8
10/01/2003 (2:01 pm)
I use Con::getData in my XML serialization code... If you take a look at that it'll give you an overview of how to walk the filed list and extract information. I based that on code existing within the engine but I can't recall which file it was.
#9
"Using C++" would be using the facilities it inherently gives you - ie, members of the class. Using getDataField to access a member of a class is more like abusing C++ :)
10/01/2003 (2:02 pm)
GetDataField is used internally by the scripting code, which is why I don't count it as using C++."Using C++" would be using the facilities it inherently gives you - ie, members of the class. Using getDataField to access a member of a class is more like abusing C++ :)
#10
10/01/2003 (2:08 pm)
I'm not sure what your getting at Chris. As others have pointed out, just use the normal C++ facilities to access your objects data.
#11
Rob: I am aware of the "normal" c++ methods to do this. Im trying to dig into torque, learn about it, understand it. Thats why Im asking questions .... after all that is the point of all of this no??
CG
10/02/2003 (6:54 am)
Ben: fair enoughRob: I am aware of the "normal" c++ methods to do this. Im trying to dig into torque, learn about it, understand it. Thats why Im asking questions .... after all that is the point of all of this no??
CG
#12
10/02/2003 (12:56 pm)
Yup... GetDataField is internal, though, so don't worry. It's used by other things, but you shouldn't use it yourself.
#13
10/02/2003 (1:27 pm)
Ok. I understand now :)
Torque 3D Owner Xavier "eXoDuS" Amado
Default Studio Name