Game Development Community

Animations will not play no matter what

by Jaron Bradley · in Torque Developer Network · 01/01/2012 (10:26 am) · 1 replies

Alright. So i've been trying to learn Torque and I'm still new but I feel like getting an animation to play should be an easy task. I tried doing it through code and it would not work so now i've tried doing it through a behavior instead. All i want to do is click on my player and have the jump animation play. Here's my behavior.

PlayAnimationBehavior.cs

if (!isObject(PlayAnimationOnClickBehavior))
{
%template = new BehaviorTemplate(PlayAnimationOnClickBehavior);
%template.friendlyName = "Play Animation On Click";
%template.behaviorType = "Mouse";
%template.description = "Plays the specified animation on Click";

%template.addBehaviorField(animationName, "Name of Animation", string, "PlayerJumpUpAnimation");
}

function PlayAnimationOnClickBehavior::onBehaviorAdd(%this)
{
echo(%this.getTemplateName());
//Turn Mouse Events On
%this.owner.setUseMouseEvents(true);
//store original animation
%this.defaultAnimation = %this.owner.getAnimationName();
}

function PlayAnimationOnClickBehavior::onMouseDown(%this)
{
echo(%this);
%this.owner.playAnimation(%this.PlayerJumpUpAnimation);
}

function PlayAnimationOnClickBehavior::onMouseUp(%this)
{
if(%this.restore){
%this.owner.playAnimation(%this.defaultAnimation);
}
}

If i open the console i see game/behaviors/PlayAnimationBehavior.cs (27): Unknown command getTemplateName
game/behaviors/PlayAnimationbehavior.cs (36): Unknown command playAnimation

How can these be unknown commands? I've tried for literally hours and i know its probably some stupid mistake I made. I appreciate any help I can get. Thanks guys... Remember. I'm new.

About the author

Recent Threads


#1
01/25/2012 (8:12 pm)
What version of Torque are you using? TGB, iTorque?

Before I go on, ensure that the object you are playing the animation with is of type Animation Sprite. I believe anything else will give you an error since it will not understand the playAnimation() method.

One more thing, I highly recommend getting Torsion if you haven't already. It makes a world of difference when trying to debug "Scripting" versus C++ coding. Best tool on this site...sometimes the console and echo outputs are not enough!

I'm am also new at this...hope this helps. If you are using iTorque, I'll post a quick resolution.