OK, Here is an example program I wrote to reproduce the error:
global PLAYER = 1
global ENEMY = 2
global bAttack as boolean
type tPawn
Health as integer
isDead as boolean
endtype
gosub _ACTORS
gosub _OBJECTS
gosub _AI_INIT
Set Camera Range 1,15000: position camera 0,0,0
sync on: sync rate 60
Do
gosub _CHECK_PLAYER_HEALTH
gosub _AI_HANDLE
gosub _DEBUG
AI update
sync
Loop
_ACTORS:
Dim Pawn(2) as tPawn
Pawn(PLAYER).Health = 100
return
_OBJECTS:
make object sphere PLAYER, 20: hide object PLAYER
make object cube ENEMY, 20: position object ENEMY,0,0,100
return
_AI_INIT:
AI start
AI set radius 60.0
AI add player PLAYER
AI add enemy ENEMY: AI set entity view range ENEMY, 500
return
_AI_HANDLE:
inc AttackDelay
if AttackDelay > 100
bAttack = 1
AttackDelay = 0
endif
select AI get entity state$(ENEMY)
case "Attack"
if bAttack and Pawn(PLAYER).Health > 0 `Health > 0 is probably not needed
damage = rnd(30) + 10
Pawn(PLAYER).Health = Pawn(PLAYER).Health - damage
bAttack = 0
endif
endcase
endselect
return
_CHECK_PLAYER_HEALTH:
if Pawn(PLAYER).Health < 0 and Pawn(PLAYER).isDead = 0
AI kill player
Pawn(PLAYER).isDead = 1 `AI KILL PLAYER will not be called again
endif
return
_DEBUG:
set cursor 0, 0
print "ENEMY, Current Action: ";AI Get Entity State$(ENEMY)
print "PLAYER HEALTH = " + str$(Pawn(PLAYER).Health)
return
THX