Clone(1) VS cloneWithBehaviors() I can't get the className
by Ezra · in Torque Game Builder · 07/30/2007 (1:49 am) · 1 replies
I'm having trouble cloning an object using cloneWithBehaviors, it has behaviors and settings that I want to duplicate, but it doesn't clone any of the Classname stuff, so I'm unable to continue using functions on it (EnemyClass::bla bla bla() etc).
If I use Clone(1) instead, I'm able to use the Classnames and functions, but I lose all my behavior settings that I was trying to bring over.
any ideas..? more info needed?
If I use Clone(1) instead, I'm able to use the Classnames and functions, but I lose all my behavior settings that I was trying to bring over.
any ideas..? more info needed?
About the author
Torque Owner Ezra
The reason I needed this is how I'm placing enemies in the level editor, I place an enemy and set the first behavior to spawner, along with the desired amount to spawn, delays, etc.. Then when it activates it spawns a duplicate of itself however many times needed, and transfers any other behaviors to the newly spawned objects.
function EnemyClass::cloneBehaviors(%this, %obj) { { %count = %this.getBehaviorCount(); if ( %count > 0 ) { for ( %i=1; %i<%count; %i++ ) { %instance = %this.getBehaviorByIndex(%i); %template = %instance.template; %behavior = %template.createInstance(); %fields = %behavior.template.getBehaviorFieldCount(); for ( %f=0; %f<%fields; %f++ ) { %field = %template.getBehaviorField(%f); %property = getWord(%field,0); %value = getWord(%field,2); %eval = "%behavior."@ %property @ " = "@ %instance @"."@ %property @";"; eval(%eval); } %obj.addBehavior(%behavior); } } }