# Help with ai code

**URL:** <https://forum.kirupa.com/t/help-with-ai-code/259813>\
**Category:** Uncategorized\
**Created:** [May 8, 2008, 10:11pm UTC](https://forum.kirupa.com/t/help-with-ai-code/259813 "2008-05-08T22:11:26Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![youngtrill](https://avatars.discourse-cdn.com/v4/letter/y/6bbea6/32.png) [@youngtrill](https://forum.kirupa.com/u/youngtrill)\
**Post date:** [May 8, 2008, 10:11pm UTC](https://forum.kirupa.com/t/help-with-ai-code/259813/1 "2008-05-08T22:11:26Z")

</div>

so far my ai does this

[http://spamtheweb.com/ul/upload/230408/6 3513\_ikkakuwitharray.swf](http://spamtheweb.com/ul/upload/230408/63513_ikkakuwitharray.swf)

i want to make him attack me when he is close enough to me and if he hits me

how to make it go to a second attack

but if ikkaku block= true and the monsters attack hits me he would go to the animation movie clip named attackblocked

i know id have to use an array but how do u make ai use arrays?

also this isnt as important for now but id like him to have a timer so it only attacks every so often

PLEASE PLEASE help me out on this guys anyone at all

---

<div class="post-metadata">

**Author:** ![ultraky](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/ultraky/32/3477_2.png) [@ultraky](https://forum.kirupa.com/u/ultraky)\
**Post date:** [May 9, 2008, 12:45am UTC](https://forum.kirupa.com/t/help-with-ai-code/259813/2 "2008-05-09T00:45:16Z")

</div>

Arrays in games are best for keeping track of multiple enemies.

I’d suggest thinking about what actions you want to happen i.e. “attack”, “defend”, “move”, “dodge”… and make functions out of those. For example an attack might be like.

```auto

public class WingEnemy extends Enemy
{
     internal function aiAttack($ikkaku:Hero):Reaction
     {
           if(!$ikkaku.block)
           {
              // where PlayerHealth is a static Singleton class
              PlayerHealth.Hurt(-10)
              
              // make attackReaction a sub-class of Reaction
              return attackReaction() 
           }

           if(ikkaku.block)
           {
              return blockReaction()
           }
     }

```

---

<div class="post-metadata">

**Author:** ![youngtrill](https://avatars.discourse-cdn.com/v4/letter/y/6bbea6/32.png) [@youngtrill](https://forum.kirupa.com/u/youngtrill)\
**Post date:** [May 10, 2008, 11:05pm UTC](https://forum.kirupa.com/t/help-with-ai-code/259813/3 "2008-05-10T23:05:07Z")

</div>

cuz, you talkin in a different language then me

i have no clue how to work classes

or singletons

im using coding on just one frame and it attaches the hero movie clip and the enemy movieclip

and the enemy respawns if its killed

but i cant get my enemy to do anything besides come to me and when its 70 away form me it stops… within reach of my weapon but its stil doing the flying animation

until its hit  
when its hit itll go to a random animation and im fixing the code now so that if he goes to “block” he wont  
lose hp

i want to have him be like a streetfighter ai

but i dont like that whole ai random thing i have

i want my monster to be a fighting monster that can block me sometimes, hit me, fall when hit by full combo and get away from me at certain hp levels and come back with an attack

until its dead

[COLOR=“Blue”] **COULD YALL VIEW MY LINK AND THEN SEE WHAT COULD BE DOEN TO THAT AI TO BETTER IT** [/COLOR]

---

<div class="post-metadata">

**Author:** ![youngtrill](https://avatars.discourse-cdn.com/v4/letter/y/6bbea6/32.png) [@youngtrill](https://forum.kirupa.com/u/youngtrill)\
**Post date:** [May 10, 2008, 11:05pm UTC](https://forum.kirupa.com/t/help-with-ai-code/259813/4 "2008-05-10T23:05:40Z")

</div>

**[COLOR=“Red”][http://spamtheweb.com/ul/upload/230408/6](http://spamtheweb.com/ul/upload/230408/6) 3513\_ikkakuwitharray.swf[/COLOR]**

thats the link sorry for double post

---

<div class="post-metadata">

**Author:** ![bombsledder](https://avatars.discourse-cdn.com/v4/letter/b/958977/32.png) [@bombsledder](https://forum.kirupa.com/u/bombsledder)\
**Post date:** [May 13, 2008, 11:06pm UTC](https://forum.kirupa.com/t/help-with-ai-code/259813/5 "2008-05-13T23:06:43Z")

</div>

wrong forum.

try Game / AI programming for help?

but what i would suggest is, if you don’t understand the language ultraky is writing code in… You should probably learn a bit about flash / actionscript or basic language elements of programming.

---

<div class="post-metadata">

**Author:** ![rahul\_7star](https://avatars.discourse-cdn.com/v4/letter/r/e36b37/32.png) [@rahul\_7star](https://forum.kirupa.com/u/rahul_7star)\
**Post date:** [May 19, 2008, 8:22am UTC](https://forum.kirupa.com/t/help-with-ai-code/259813/6 "2008-05-19T08:22:55Z")

</div>

[quote=youngtrill;2324525]**[COLOR=Red][http://spamtheweb.com/ul/upload/230408/6](http://spamtheweb.com/ul/upload/230408/6) 3513\_ikkakuwitharray.swf[/COLOR]**

thats the link sorry for double post[/quote]

Do some more animation to zombie like falling to ground and a bit more , then i will tell you the logic
