random value variables. need help

You must understand the Game Editor concepts, before post here.

random value variables. need help

Postby j2graves » Thu Sep 10, 2009 2:27 am

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?
No games to my name...
User avatar
j2graves
 
Posts: 1302
Joined: Thu Aug 16, 2007 6:42 pm
Location: on the other side of infinity
Score: 19 Give a positive score

Re: random value variables. need help

Postby Hblade » Thu Sep 10, 2009 2:34 am

Use rand(number)
Subscribe to my YouTube? - Yes| No
User avatar
Hblade
 
Posts: 4455
Joined: Fri Dec 08, 2006 11:14 pm
Score: 181 Give a positive score

Re: random value variables. need help

Postby j2graves » Thu Sep 10, 2009 2:38 am

well that's what I used. sorry I didn't make that clear.
No games to my name...
User avatar
j2graves
 
Posts: 1302
Joined: Thu Aug 16, 2007 6:42 pm
Location: on the other side of infinity
Score: 19 Give a positive score

Re: random value variables. need help

Postby skydereign » Thu Sep 10, 2009 3:05 am

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


Return to Advanced Topics

Who is online

Users browsing this forum: No registered users and 1 guest