Page 1 of 1

random animations and codes

PostPosted: Sat Aug 08, 2009 8:26 pm
by Azou
Yuuup!!
I wanted to ask something: how can I make random animations and codes? That is for an enemy. The problem is that there are many codes in the project, but I just want to use those one which are made fir the enemy in a randm way.how can I do??

Re: random animations and codes

PostPosted: Sat Aug 08, 2009 11:45 pm
by skydereign
If I understand you, it will depend on the way you have the codes implemented, and the trigger. Since animations can be categorized through animindex, you can use this in combination with random. I believe the function is getAnimName. Now if you put a rand in that it will return a random animation. This is the part that I am really not sure on, each animation has a set of code? If so, then in the draw actor, use the animindex in a switch statement. You can use the getAnimIndex to clarify, otherwise you need to know each animation's index.

Code: Select all
switch(animindex)
{
    case getAnimIndex("run"):
    ..code for this one
    break;
    // and so on
}

Re: random animations and codes

PostPosted: Sun Aug 09, 2009 3:33 pm
by Azou
Er...What do you mean by "switch statement" and by"put a rand"?
Ok, then if I understood: I must have a cod for each animation, after on the draw actor of the enemy, I must put the code you gave me?
Anyway, thanks for you help!!^-^! :mrgreen:

Re: random animations and codes

PostPosted: Sun Aug 09, 2009 7:50 pm
by skydereign
A switch statement would be better fitted. It breaks the variable values into cases.
Code: Select all
switch(animindex)
{
    case 0: // if animindex==0
    //code
    break;
    case 1: // if animindex==1
    break;
}


As for rand, it is a function.
Code: Select all
rand(2);

This will return 0 or 1. So if you combine that with getAnimName, within the ChangeAnimation, it will change the animation to a random one.
Code: Select all
ChangeAnimation("Event Actor", getAnimName(rand(8)), FORWARD);

This returns an animation between 0-7 randomly.

Re: random animations and codes

PostPosted: Mon Aug 10, 2009 2:01 pm
by Azou
Okay! I got it!! Thanks!+1