How to use GetAnimName?

Non-platform specific questions.

How to use GetAnimName?

Postby lverona » Mon May 07, 2012 6:39 pm

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?
lverona
 
Posts: 221
Joined: Tue Apr 24, 2012 11:54 am
Score: 1 Give a positive score

Re: How to use GetAnimName?

Postby skydereign » Mon May 07, 2012 6:45 pm

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);
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: How to use GetAnimName?

Postby lverona » Mon May 07, 2012 7:08 pm

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.
lverona
 
Posts: 221
Joined: Tue Apr 24, 2012 11:54 am
Score: 1 Give a positive score

Re: How to use GetAnimName?

Postby skydereign » Mon May 07, 2012 7:23 pm

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.
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: How to use GetAnimName?

Postby lverona » Mon May 07, 2012 7:38 pm

So you are saying that there is no way to get to know what animation the actor is using right now?
lverona
 
Posts: 221
Joined: Tue Apr 24, 2012 11:54 am
Score: 1 Give a positive score

Re: How to use GetAnimName?

Postby skydereign » Mon May 07, 2012 7:41 pm

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
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: How to use GetAnimName?

Postby lverona » Mon May 07, 2012 8:01 pm

Would this then be correct?

if (getAnimName(animindex)=="goleft"){do this}else {do that}
lverona
 
Posts: 221
Joined: Tue Apr 24, 2012 11:54 am
Score: 1 Give a positive score

Re: How to use GetAnimName?

Postby skydereign » Mon May 07, 2012 8:07 pm

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)
{
    //
}
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: How to use GetAnimName?

Postby lverona » Mon May 07, 2012 8:24 pm

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!
lverona
 
Posts: 221
Joined: Tue Apr 24, 2012 11:54 am
Score: 1 Give a positive score


Return to General

Who is online

Users browsing this forum: No registered users and 1 guest

cron