Page 1 of 1

random value variables. need help

PostPosted: Thu Sep 10, 2009 2:27 am
by j2graves
heya, sorry for the long absence. well anyway, I'm back.

my problem is this: I'm trying to develop a form of AI, and the way I was going to do it was I was going to give the actor an integer variable. I wanted the actor to do a random attack. so I set it to give the variable a random value, and that the actor would go through a specific animation depending on the value of the variable. the trouble is, the variable didn't seem to affect its animation. yes, it did change animation, but it only selected a particular one, and no matter how many times I opened the game, it would always be playing that same one in a loop. could someone give me some suggestions concerning AI and random actions?

Re: random value variables. need help

PostPosted: Thu Sep 10, 2009 2:34 am
by Hblade
Use rand(number)

Re: random value variables. need help

PostPosted: Thu Sep 10, 2009 2:38 am
by j2graves
well that's what I used. sorry I didn't make that clear.

Re: random value variables. need help

PostPosted: Thu Sep 10, 2009 3:05 am
by skydereign
Well, here are some examples. This assumes all you need is change of animation, but the latter one can have other code inserted. Both of these are assuming that you have an event that triggers the animation change, and these codes would be inserted. If the trigger is constant, than you would want to set a variable, maybe a variable like animation_finish, and/or use NO_CHANGE for the anim state.
Code: Select all
ChangeAnimation("enem_player", getAnimName(rand(5)), FORWARD)


This assumes there are five animations to choose from, and it will pick one of them. The next one is more dynamic, as you can choose which attacks, and also the chances of the attack. If you wanted a higher chance of attack_0, you would just insert it as such.

Code: Select all
int randomAnim = rand(3);
switch(randomAnim)
{
    case 0:
    ChangeAnimation("enem_player", "attack_0", FORWARD);
    break;

    case 1:
    ChangeAnimation("enem_player", "attack_1", FORWARD);
    break;

    case 2:
    ChangeAnimation("enem_player", "attack_2", FORWARD);
    break;
}