Quick question on adding behaviors
by Law Rus · in Torque Game Builder · 01/23/2008 (1:10 pm) · 1 replies
I was follow the asteroids tutorial for the score board, but I'm having trouble working out how to a behavior through script.
I can add the behavior at design time and roughly understand how it all works, however, I want to add it to any enemies that are spawned in through code.
Here is the the behavior code
if (!isObject(ScorePointsBehavior))
{
%template = new BehaviorTemplate(ScorePointsBehavior);
%template.friendlyName = "Score Points";
%template.behaviorType = "Game";
%template.description = "Gives the object a point value for scoring purposes";
%template.addBehaviorField(pointValue, "How much the object is worth", int, 10);
%template.addBehaviorField(counter, "The score counter object", object, "", t2dSceneObject);
}
function ScorePointsBehavior::onRemoveFromScene(%this, %scenegraph)
{
%counter = %this.counter.getBehavior("DisplayScoreBehavior");
if (!isObject(%counter))
return;
$currentScore = $currentScore + %this.pointValue;
%counter.updateScore();
}
so would I call 'ScorePointsBehavoir'? I read through the rest of the tutorial but I can't seem to find it anywhere.
I can add the behavior at design time and roughly understand how it all works, however, I want to add it to any enemies that are spawned in through code.
Here is the the behavior code
if (!isObject(ScorePointsBehavior))
{
%template = new BehaviorTemplate(ScorePointsBehavior);
%template.friendlyName = "Score Points";
%template.behaviorType = "Game";
%template.description = "Gives the object a point value for scoring purposes";
%template.addBehaviorField(pointValue, "How much the object is worth", int, 10);
%template.addBehaviorField(counter, "The score counter object", object, "", t2dSceneObject);
}
function ScorePointsBehavior::onRemoveFromScene(%this, %scenegraph)
{
%counter = %this.counter.getBehavior("DisplayScoreBehavior");
if (!isObject(%counter))
return;
$currentScore = $currentScore + %this.pointValue;
%counter.updateScore();
}
so would I call 'ScorePointsBehavoir'? I read through the rest of the tutorial but I can't seem to find it anywhere.
About the author
Associate Mike Lilligreen
Retired T2Der
where %this.spawnObject is defined in the behavior field of the spawn area behavior. Hope that helps.