random animations and codes

Game Editor comments and discussion.

random animations and codes

Postby Azou » Sat Aug 08, 2009 8:26 pm

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??
User avatar
Azou
 
Posts: 514
Joined: Thu Sep 13, 2007 1:12 pm
Score: 35 Give a positive score

Re: random animations and codes

Postby skydereign » Sat Aug 08, 2009 11:45 pm

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

Re: random animations and codes

Postby Azou » Sun Aug 09, 2009 3:33 pm

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:
User avatar
Azou
 
Posts: 514
Joined: Thu Sep 13, 2007 1:12 pm
Score: 35 Give a positive score

Re: random animations and codes

Postby skydereign » Sun Aug 09, 2009 7:50 pm

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

Re: random animations and codes

Postby Azou » Mon Aug 10, 2009 2:01 pm

Okay! I got it!! Thanks!+1
User avatar
Azou
 
Posts: 514
Joined: Thu Sep 13, 2007 1:12 pm
Score: 35 Give a positive score


Return to GE - General

Who is online

Users browsing this forum: No registered users and 1 guest