This is a high level approach that I take to AI. I am not an expert, but I've managed to get some things to work okay in my games. AI is all about States.

I have been using a skill to store a number. Depending on the number, the AI will behave in a certain way, this is it's "state." Now depending on what happens to the AI, i.e. getting shot, losing sight of the player, etc... the state may change. The number in that skill changes, and therefore the behavior changes.

So I will set up a while loop like this:

Quote:

while(1)
{
if(my.skill10 == 1)
{
Do_something();
}
else if(my.skill10 == 2)
{
Do_something_else();
}

if(something_happens)
{
my.skill10 = 1;
}
else if(something_else_happens)
{
my.skill10 = 2;
}
wait(1);
}