# My AI isn't working

hi guys, just wondering if u could take a look at my simple AI. I know the problem is sumthing simple but i cant find out whats wrong with it. Any help would be great, thanx.

`````` action = Math.ceil(Math.random()*100);
aTimer = 0;
eattack = false;
//
function enemyAttack() {
aTimer++;
if (aTimer == 180) {
aTimer = 0;
if (action>=0 && action<45) {
_root.dino.gotoAndStop("walk");
eattack = true;
//
} else if (action>=45 && action<70) {
_root.dino.gotoAndStop("chomp");
eattack = true;
//
} else if (action>=70 && action<100) {
_root.dino.gotoAndStop("tailslap");
eattack = true;
//
} else {
_root.dino.gotoAndStop("stand");
eattack = true;
}
}
}
if (eattack=false) {
enemyAttack();
}

``````

i traced the aTimer and it duznt count up so for sum reason the timer isnt being initiated. hope that helps.

You should have:

if(eattack == false)

`````` action = Math.ceil(Math.random()*100);
aTimer = 0;
eattack = false;
//
function enemyAttack() {
aTimer++;
eattack = true;
if (aTimer == 180) {
aTimer = 0;
if (action>=0 && action<45) {
_root.dino.gotoAndStop("walk");
//
} else if (action>=45 && action<70) {
_root.dino.gotoAndStop("chomp");
//
} else if (action>=70 && action<100) {
_root.dino.gotoAndStop("tailslap");
//
} else {
_root.dino.gotoAndStop("stand");
}
}
}
if (eattack == false) {
enemyAttack();
}

``````

ok i fixed that, but now it just counts to 1. any help?

Change the first line to this:

action = random(100)+1;

hhmm. its still not working. i attached the FLA with sum quickly drawn graphics.

I don’t think I can help. I don’t have flash on this computer and the internet isn’t working on mine. Someone else will know.

Nevermind. It’s working now. I don’t know why, but this works:

yay thank you very much.