EDIT: You haven't given each enemy its own state. You've created the array just fine, but you use one variable for all of the enemies so the arrays aren't even being used. When using arrays, you need to refer to specific array "slots" or, as they are called in my tutorial, "dressers". Right now you're just doing the same thing once for each enemy object. Try this, The enemy object numbers and enemy states are both stored in arrays now:
remstart
trying to get multiple objects to use same code with array
remend
autocam off : position camera 0,55,-60
dim enemystate(3)
dim enemy(3)
for e = 1 to 3
enemystate(e)=1
next e
`enemies
for n=1 to 3
make object cube n,5 : color object n,rgb(255,0,0)
position object n,rnd(30),2,rnd(50)-rnd(50)
enemy(n)=n `set this enemy to use this object number
next n
`player
make object sphere 8,5 : color object 8,rgb(0,0,200)
`ground
make object box 9,90,0.1,90 : color object 9,rgb(0,200,0)
position object 9,0,-3,0
do
for e=1 to 3
if enemystate(e)=1
point object enemy(e),object position x(8),object position y(enemy(e)),object position z(8)
move object enemy(e),0.5
if distance(8,enemy(e))<5 then enemystate(e)=2
endif
if enemystate(e)=2
color object enemy(e),rgb(rnd(255),0,0)
text 200,200,"yeah! :P"
enemystate(e)=3
endif
if enemystate(e)=3
move object enemy(e),-0.8
if distance(8,enemy(e))>60 then enemystate(e)=1
endif
next e
`camera
rotate camera camera angle x()+mousemovey(),camera angle y()+mousemovex(),0
if mouseclick()=1 then move camera 1
if mouseclick()=2 then move camera -1
if upkey() then move object 8,0.8
if leftkey() then turn object left 8,1
if rightkey() then turn object right 8,1
loop
`*** distance ***
function distance(o,o2)
ox#=object position x(o2)
oz#=object position z(o2)
oy#=object position y(o2)
dx#=object position x(o)-ox#
dz#=object position z(o)-oz#
dy#=object position y(o)-oy#
dist#=sqrt((dx#*dx#)+(dz#*dz#)+(dy#*dy#))
endfunction dist#
I basically just took your code, and put "(e)" next to every place where your wrote "enemy" or "enemystate". I also changed your for/next variable to "e".
Also, on a side note, you may want to add SYNC ON and SYNC RATE 60 to the top of your code. Then, put SYNC right before the word "loop". It will make things look smoother
<---Spell casting battle game!