Getting an objects console variable in the engine
by Bryce · in Torque Game Engine · 08/02/2008 (10:53 am) · 7 replies
Hello again,
Say I have an object with a variable team set
In script, I could get the value of team using MyObject.team. How would I do this in C++? Is there a way to get a variable that's part of an object or can I only do this with global variables?
Say I have an object with a variable team set
%obj = new ScriptObject(MyObject)
{
team = 1;
}In script, I could get the value of team using MyObject.team. How would I do this in C++? Is there a way to get a variable that's part of an object or can I only do this with global variables?
#2
08/02/2008 (12:13 pm)
Thank you! This probably won't matter, but what is the 0 parameter in getDataField() for?
#3
08/02/2008 (12:20 pm)
Btw, If you find yourself accessing a dynamic field in C++ you should probably make it a regular static field.
#4
08/02/2008 (12:20 pm)
It's the element count in the form of a string (i.e. here it is a NULL pointer; should have used that). In this case, it's needed to disambiguate between two versions of getDataField. If team was indexed, you could use e.g. getDataField( StringTable->insert( "team" ), "1" ) to get the second element.
#5
So: Correction
There are no two getDataField methods. The second parameter is the array index--it's just a required parameter and that's it.
08/02/2008 (12:42 pm)
Males aren't made for multitasking... at least I am not. Confused something here...So: Correction
There are no two getDataField methods. The second parameter is the array index--it's just a required parameter and that's it.
#6
08/02/2008 (1:21 pm)
Okay, so if team were an array (team[0], team[1], etc), then I would change the array index appropriately, and if it isn't an array, we just leave it at zero?
#7
to get the value of a field that is not indexed, you would write
and to get the first value in an indexed field, you would write
08/02/2008 (1:57 pm)
Yes. If, though, by "zero" you mean the 0 above, then it's not quite right. Passing 0 (i.e. a NULL pointer) is different from passing "0" (the zeroth index), i.e.to get the value of a field that is not indexed, you would write
const char* value = myObject->getFieldData( StringTable->insert( "team" ), NULL );
and to get the first value in an indexed field, you would write
const char* value = myObject->getFieldData( StringTable->insert( "team" ), "0" );
Associate Rene Damm
//EDIT
Oopss, corrected myObject to be a pointer.