How to list custom SimObject attributes in TS?
by Eero Karvonen · in Torque 2D Beginner · 09/18/2013 (11:10 am) · 2 replies
Hi,
I'm quite new to TorqueScript, and couldn't find any documentation on how to list self-added variables attached to a SimObject. For example in the following script,
I see I can access these attributes with the "." operator. But how are they actually stored, and how can they be listed via script? I've tried to dump the internal fields and dynamic fields of the object, but they don't seem to exist in that realm.
I'm quite new to TorqueScript, and couldn't find any documentation on how to list self-added variables attached to a SimObject. For example in the following script,
%obj = new ScriptObject()
{
a = "1";
b = "2";
c = "3";
};I see I can access these attributes with the "." operator. But how are they actually stored, and how can they be listed via script? I've tried to dump the internal fields and dynamic fields of the object, but they don't seem to exist in that realm.
#2
Your snippet does exactly what I had already tried, and it did work indeed after I figured out the problem was elsewhere. My bad. :)
09/18/2013 (12:31 pm)
Thanks for the quick response, Mike!Your snippet does exactly what I had already tried, and it did work indeed after I figured out the problem was elsewhere. My bad. :)
Associate Mike Lilligreen
Retired T2Der
They should exist when you dump the fields - custom attributes on objects are called dynamic fields. Here is an example on how to access them:
%count = %example.getDynamicFieldCount(); for (%i = 0; %i < %count; %i++) { %fieldName = %example.getDynamicField(%i); %fieldValue = %example.getFieldValue(%fieldName); echo(%fieldName @ " = " @ %fieldValue); }I took that example from the upcoming doxygen write up that will be merged into the development branch soon. A sneak peek:
github.com/GarageGames/Torque2D/blob/torqueScriptDocs/engine/source/sim/simObjec...