enemyAI()

I’m trying to code my own battle engine. Its not exactly complex, but not basic either. Unfortunately, I’m having trouble with the enemy AI when it comes to randomizing enemy attacks. Take a look at this SWF:

http://spamtheweb.com/ul/upload/160409/75715_Basic_Battle_State_Engine.php

When it comes to the Beam Attack, both “Slash” and “Beam” comes up as “currentAttack”. I have no idea why.

I like to use functions as a basis for my coding and just activate them in the frame when needed. Heres my enemyAI(); function.

function enemyAI() {
    var enemyAttackList = new Array();
    switch (enemyname) {
        case "Dummy" :
            if (_root.battlestatus == enemyname+" Turn") {
                enemyAttackList = [];
                enemyAttackList.push("Slash","Pout","Rage");
                currentAttack = enemyAttackList[random(2)];
                currentAttack = currentAttack;
                if (currentAttack == "Slash") {
                    trace(currentAttack);
                    _root.slashmc._x = _root.player._x;
                    _root.slashmc._y = _root.player._y;
                    _root.slashmc.play();
                    enemydamagecount();
                    _root.battlestatus = enemyname+" slashes "+playername;

                }
            }
            break;
        case "Bullseye" :
            if (_root.battlestatus == enemyname+" Turn") { //If it is enemy's turn (This is triggered by the code in the attack mcs such as "Slash")
                enemyAttackList = []; //Clears the enemyAttackList for use of a new mob)
                enemyAttackList.push("Slash","Beam","Pinpoint"); //Adds new set of attacks for designated mob
                currentAttack = enemyAttackList[random(2)]; //randomizes the set of attacks
                if (currentAttack == "Slash") { 
                    _root.slashmc._x = _root.player._x;
                    _root.slashmc._y = _root.player._y;
                    _root.slashmc.play();
                    enemydamagecount();
                    _root.battlestatus = enemyname+" slashes "+playername;
                    
            
            } else  if(currentAttack == "Beam") {
                        _root.beamattack.play();
enemydamagecount();
                        
                    }
               else if(currentAttack == "Pinpoint") {
                   trace("Pinpoint Attack")
               }
        }
        
    }
}

Don’t mind the Dummy code, I haven’t fully programmed him yet. Basically, I have a MovieClip for every attack. In this case, its SlashMC.

On the first frame of SlashMC, I have this code:

if(_root.currentAttack == "Slash") {
// trace("slashof")
_root.battletest2 = "Slash Receives!"
play();
} else {
stop();
}

Last frame I have:

if(_root.battlestatus == _root.playername + " slashes " + _root.enemyname) {
_root.battlestatus =_root.enemyname+" Turn"
} else {
    _root.battlestatus = "Your Turn"
}
_root.playerdmgdisp = ""
_root.enemydmgdisp = ""
_root.currentAttack = ""
_root.battletest2 = ""

I tried tracing, debugging and nearly everything I can think of. I don’t usually depend on forums, but I don’t know what to do anymore. Can anyone help?

If this still confuses you, heres the fla.

http://spamtheweb.com/ul/upload/160409/75862_Basic_Battle_State_Engine.fla