Game Development Community

Add dynamic field from script

by Owen Ortmayer · in Torque Game Engine · 05/04/2004 (9:30 am) · 3 replies

Is there a way to add a dynamic field on the fly from a script. I want to have a set of objects that are the same base class, but differentiate thier behavior thorugh scripts. I want the ability to add dynamic fields as needed that will show up in the world editor inspector. You can override the datablock::create() function and add in dynamic fields:
function StaticShapeData::create(%data)
{
   // The mission editor invokes this method when it wants to create
   // an object of the given datablock type.
   %obj = new StaticShape() {
      dataBlock = %data;
      dynamicField = "thisIsADynamicField";
   };
   return %obj;
}
but that only applies to the base object(StaticShape here).

#1
05/04/2004 (11:54 am)
Well here's what I came up with:
function StaticShapeData::create(%data)
{
   //see if we want to do something special
   switch$( %data.getName() )
   {
		case "TypeThatNeedsDynamicField":
			%obj = new StaticShape() 
			{
				dataBlock = %data;
				dynamicFiled = "thisIsADynamicField";
			};
			return %obj;
   }
   
   //do default behavior
   %obj = new StaticShape() {
      dataBlock = %data;
   };
   return %obj;
}
#2
05/04/2004 (1:54 pm)
You can set a dynamic variable from script at any time.

Just use
%object.vairableName = var;
#3
10/28/2006 (10:52 pm)
The correct way should be %object._[%variableName]=varvalue;