Get properties of an object
by Anthony Merlo · in Torque Game Engine Advanced · 01/28/2009 (3:20 pm) · 5 replies
how would I get the properties of an object and assign it to a variable?
For instance I want to get the Name of an object (#2233) I named "box" using the World Editor Inspector.
In the script I would type something like
This is wrong of course, but how would I go about doing something like that in ver 1.8?
Also, is there a list of all the fields available to "get" or "set" on the object?
Thanks
For instance I want to get the Name of an object (#2233) I named "box" using the World Editor Inspector.
In the script I would type something like
$name = 2233.getName()
This is wrong of course, but how would I go about doing something like that in ver 1.8?
Also, is there a list of all the fields available to "get" or "set" on the object?
Thanks
About the author
#2
would return the parent group name of the object I clicked on.
01/28/2009 (5:29 pm)
Thanks! Using that I was able to figure out that using:%name = %object.getFieldValue(parentGroup);
would return the parent group name of the object I clicked on.
#3
For instance if I want to change the color shading of a tree. I can do this:
I'd check the properties of the tree and the value for the custom ambient lighting has changed to 9 9 0 9 and the check mark is checked on use ambient lighting, but the trees appearance doesn't change. if I click the check mark off and back on again, then it will change.
is there some type of update command I have to send to the object to make the changes take place?
01/28/2009 (10:03 pm)
I use %object.setFieldValue to change a field on the object but it doesn't seem to actually change anything. I check the object with the world inspector and the field has changed.For instance if I want to change the color shading of a tree. I can do this:
%object.setFieldValue(customAmbientLighting, "9 9 0 9"); %object.setFieldValue(useCustomAmbientLighting, true);
I'd check the properties of the tree and the value for the custom ambient lighting has changed to 9 9 0 9 and the check mark is checked on use ambient lighting, but the trees appearance doesn't change. if I click the check mark off and back on again, then it will change.
is there some type of update command I have to send to the object to make the changes take place?
#4
01/28/2009 (10:05 pm)
A lot of this is dependent on the implementation of the object - whether the field auto updates or not. If it doesn't, you can call InspectPostApply to force it to update (like the inspector does).
#5
Sorry for my lack of knowledge but I'm having trouble locating the correct syntax for InspectPostApply.
The documentation says SimObject::inspectPostApply() but that wasn't helpful.
Could you let me know how I would apply that to my script?
Thanks
01/28/2009 (11:04 pm)
Thanks for the quick reply.Sorry for my lack of knowledge but I'm having trouble locating the correct syntax for InspectPostApply.
The documentation says SimObject::inspectPostApply() but that wasn't helpful.
Could you let me know how I would apply that to my script?
Thanks
Associate Jaimi McEntire
King of Flapjacks
$name = %object.name;
But if you are wanting to enumerate the fields and values, you can do it
like this:
%fldcnt = %object.getFieldCount(); for (%i=0;%i<%fldcnt;%i++) { // Gets the field name and the field value %fldname = %object.getField(%i); %fldvalue = %object.getFieldValue(%fldname); }Fields can also be added dynamically:
%object.MyNewField = "10"; // creates a new dynamic field and assigns it.
You enumerate these differently:
%fldcnt = %object.getDynamicFieldCount(); for (%i=0;%i<%fldcnt;%i++) { // Gets the field name and the field value %fldname = %object.getDynamicField(%i); %fldvalue = %object.getFieldValue(%fldname); }