Page 1 of 1

How to use GetAnimName?

PostPosted: Mon May 07, 2012 6:39 pm
by lverona
Hey guys!

Searched the forums, read the Script Reference, tried it out in the Script Editor - but I cannot get the function to work. Can someone please post an example of usage - how do you get the animation name of an Event Actor?

Re: How to use GetAnimName?

PostPosted: Mon May 07, 2012 6:45 pm
by skydereign
So you know, the script reference's example is bad, since a text actor doesn't have an animation.
Code: Select all
getAnimName(animindex); // this returns the name of the event actor's animation


If you are using an int to hold the animation, you can use it with getAnimName to change the event actor's animation to it.
Code: Select all
ChangeAnimation("Event Actor", getAnimName(var), FORWARD);

Re: How to use GetAnimName?

PostPosted: Mon May 07, 2012 7:08 pm
by lverona
Yeah, but what if I do not know the animIndex? I mean, I have an "enemy" character which goes back and forth. When he goes right he has one animation, when he goes left - another. When an event happens - I need to know what direction the enemy was facing.

Re: How to use GetAnimName?

PostPosted: Mon May 07, 2012 7:23 pm
by skydereign
If you don't know it, changing to it would be impossible. But, the easy fix is to know it, or a way of finding out. For instance, if you had an actor that only has two animations, right and left. If it has a dir variable, 0 can stand for moving right, and 1 can stand for moving left.
Code: Select all
// the event that makes the actor move left
dir=1;
ChangeAnimation("Event Actor", getAnimName(dir), FORWARD);


Alternatively since there are only two animations, you can use this for changing direction (this is using a system to figure out which animation).
Code: Select all
ChangeAnimation("Event Actor", getAnimName(animindex==0), FORWARD);


Same thing can be applied to more than two directions, or more types of animations. For instance if you use the state method, you could just use getAnimName(state) for all animation names. The idea though is to order your animations in a way that is predictable.

Re: How to use GetAnimName?

PostPosted: Mon May 07, 2012 7:38 pm
by lverona
So you are saying that there is no way to get to know what animation the actor is using right now?

Re: How to use GetAnimName?

PostPosted: Mon May 07, 2012 7:41 pm
by skydereign
No... I already said you can do that. Just use the animindex variable in tandem with the getAnimName function.
skydereign wrote:
Code: Select all
getAnimName(animindex); // this returns the name of the event actor's animation

Re: How to use GetAnimName?

PostPosted: Mon May 07, 2012 8:01 pm
by lverona
Would this then be correct?

if (getAnimName(animindex)=="goleft"){do this}else {do that}

Re: How to use GetAnimName?

PostPosted: Mon May 07, 2012 8:07 pm
by skydereign
No, you can't compare strings like that. You have to use strcmp if you want to do that. Though seeing as you are using a string constant, I don't recommend using getAnimName at all. But, if you wanted to make that code work it would look like this.
Code: Select all
if(strcmp(getAnimName(animindex), "goleft")==0) // strcmp returns a 0 when the strings are the same
{
    // do this
}
else
{
    // do that
}


So instead of using strcmp (since string compare is much slower than comparing integers) I'd recommend you use #defines.
Global Code
Code: Select all
#define goleft 4
// in global code make definitions that stand for the proper animindexes (in this example goleft would be the 5th animation)


That way you can just use this.
Code: Select all
if(animindex==goleft)
{
    //
}

Re: How to use GetAnimName?

PostPosted: Mon May 07, 2012 8:24 pm
by lverona
So animindex is just the order number of the animation in the animation list of the character?

Looks like I can just use if(animindex==2) {} - and that's all! Just tried it, it works!